Created
September 30, 2011 17:09
-
-
Save seanlin/1254376 to your computer and use it in GitHub Desktop.
HTML5 Geolocation with Google Map API V3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="map-big" style="width:500px; height:300px"></div> | |
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> | |
<script type="text/javascript"> | |
var locations = [ | |
["Tanglin", 1.29559, 103.825607, 3], | |
["Orchard Turn", 1.30431, 103.831905, 2], | |
["Cityhall", 1.29308, 103.852226, 1], | |
]; | |
if (navigator.geolocation) { | |
navigator.geolocation.getCurrentPosition(function(position) { | |
showMap(position.coords.latitude, position.coords.longitude); | |
}); | |
} | |
else { | |
} | |
function showMap(geolat, geolng) { | |
var map = new google.maps.Map(document.getElementById('map-big'), { | |
zoom: 10, | |
center: new google.maps.LatLng(geolat, geolng), | |
mapTypeId: google.maps.MapTypeId.ROADMAP | |
}); | |
var infowindow = new google.maps.InfoWindow({ | |
maxWidth: 200 | |
}); | |
var marker, i; | |
for (i = 0; i < locations.length; i++) { | |
marker = new google.maps.Marker({ | |
animation: google.maps.Animation.DROP, | |
position: new google.maps.LatLng(locations[i][1], locations[i][2]), | |
map: map | |
}); | |
google.maps.event.addListener(marker, 'click', (function(marker, i) { | |
return function() { | |
infowindow.setContent(locations[i][0]); | |
infowindow.open(map, marker); | |
} | |
})(marker, i)); | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
doesn't work