Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@karlcow
Created December 6, 2012 01:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karlcow/4221190 to your computer and use it in GitHub Desktop.
Save karlcow/4221190 to your computer and use it in GitHub Desktop.
experiment of accessing Microdata in an html page with microdata API
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Microdata and Geolocation</title>
</head>
<body>
<ul>
<li itemscope itemtype="http://schema.org/Place">
<span itemprop="name">Tsujido</span>
<div itemprop="geo"
itemscope
itemtype="http://schema.org/GeoCoordinates">
<meta itemprop="latitude" content="35.336833"/>
<meta itemprop="longitude" content="139.447083"/>
</div>
</li>
<li itemscope itemtype="http://schema.org/Place">
<span itemprop="name">Meguro</span>
<div itemprop="geo"
itemscope
itemtype="http://schema.org/GeoCoordinates">
<meta itemprop="latitude" content="35.633983"/>
<meta itemprop="longitude" content="139.71600"/>
</div>
</li>
</ul>
<script>
var places = document.getItems('http://schema.org/Place');
console.log(places);
for (var i = places.length - 1; i >= 0; i--) {
longitude = places[i].properties['geo'][0].properties['longitude'][0].itemValue;
console.log(longitude);
};
</script>
</body>
</html>
@karlcow
Copy link
Author

karlcow commented Dec 7, 2012

Now trying to make it RDFa Lite compliant

<ul vocab="http://schema.org/">
    <li typeof="Place">
        <span property="name">Tsujido</span>
        <div property="geo"
             typeof="GeoCoordinates">
             <meta property="latitude" content="35.336833"/>
             <meta property="longitude" content="139.447083"/>
             </div>
        </li>
    <li typeof="Place">
        <span property="name">Meguro</span>
        <div property="geo"
             typeof="GeoCoordinates">
             <meta property="latitude" content="35.633983"/>
             <meta property="longitude" content="139.71600"/>
             </div>
        </li>
</ul>

@karlcow
Copy link
Author

karlcow commented Dec 7, 2012

One issue is that there is no JavaScript API for accessing RDFa Lite data. Maybe a shim on top of microdata API could do the job?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment