Created
August 14, 2012 18:30
-
-
Save tyrauber/3351515 to your computer and use it in GitHub Desktop.
HTML5 JS Geolocation Reverse-Geolocation
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 latlng; | |
var address; | |
geocoder = new google.maps.Geocoder(); | |
function success(position) { | |
var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); | |
geocoder.geocode({'latLng': latlng}, function(results, status) { | |
if (status == google.maps.GeocoderStatus.OK) { | |
if (results[1]) { | |
address = results[1].formatted_address; | |
console.log(results[1]); | |
// Render Stuff | |
}else{ | |
error("Unable to reverse Geocode"); | |
} | |
} | |
}); | |
} | |
function error(msg) { | |
console.log(msg); | |
} | |
if (navigator.geolocation) { | |
navigator.geolocation.getCurrentPosition(success, error); | |
} else { | |
error('HTML 5 Geolocation not supported'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment