Skip to content

Instantly share code, notes, and snippets.

@andreia
Created November 9, 2010 15:11
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 andreia/669201 to your computer and use it in GitHub Desktop.
Save andreia/669201 to your computer and use it in GitHub Desktop.
Geolocation using W3C Geolocation API - http://dev.w3.org/geo/api/spec-source.html
<html>
<head>
<title>Example: Geolocation using W3C Geolocation API</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
function initialize(){
var myOptions = { zoom: 8, mapTypeId: google.maps.MapTypeId.HYBRID };
var map = new google.maps.Map(document.getElementById("map"), myOptions);
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
var currentLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
map.setCenter(currentLocation);
var marker = new google.maps.Marker({ position: currentLocation, map: map, title:"you are here" });
});
}
}
</script>
</head>
<body onload="initialize()">
<div id="map" style="height: 100%;"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment