Created
August 26, 2011 19:05
-
-
Save dbrajkovic/1174166 to your computer and use it in GitHub Desktop.
HTML5 Geolocation script example
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
var map; | |
var geocoder; | |
function addAddressToMap(response) | |
{ | |
map.clearOverlays(); | |
if (!response || response.Status.code != 200) | |
{ | |
alert("Sorry, we were unable to geocode that address"); | |
} | |
else | |
{ | |
place = response.Placemark[0]; | |
point = new GLatLng(place.Point.coordinates[1], | |
place.Point.coordinates[0]); | |
marker = new GMarker(point); | |
map.setCenter(point, 13); | |
map.addOverlay(marker); | |
document.getElementById('address').innerHTML = place.address; | |
} | |
} | |
function initialize() | |
{ | |
map = new GMap2(document.getElementById("map_image")); | |
map.setCenter(new GLatLng(34, 0), 1); | |
map.setUIToDefault(); | |
geocoder = new GClientGeocoder(); | |
if (navigator.geolocation) | |
{ | |
navigator.geolocation.getCurrentPosition(function(position) | |
{ | |
document.getElementById('latitude').innerHTML = position.coords.latitude; | |
document.getElementById('longitude').innerHTML = position.coords.longitude; | |
var coord = position.coords.latitude+","+position.coords.longitude; | |
geocoder.getLocations(coord, addAddressToMap); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment