Skip to content

Instantly share code, notes, and snippets.

@tyrauber
Created August 14, 2012 18:30
Show Gist options
  • Save tyrauber/3351515 to your computer and use it in GitHub Desktop.
Save tyrauber/3351515 to your computer and use it in GitHub Desktop.
HTML5 JS Geolocation Reverse-Geolocation
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