Created
October 5, 2012 08:06
-
-
Save joeljunstrom/3838685 to your computer and use it in GitHub Desktop.
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
function locateMe() { | |
var supportsLocation = function() { | |
return 'geolocation' in navigator; | |
} | |
var geocoder = new google.maps.Geocoder(); | |
var onError = function(error) { | |
console.log(error); | |
}; | |
var onSuccess = function(response) { | |
var lat = response.coords.latitude, | |
lng = response.coords.longitude, | |
latlng = new google.maps.LatLng(lat, lng); | |
geocoder.geocode({'latLng': latlng}, function(results, status) { | |
if (status == google.maps.GeocoderStatus.OK) { | |
if (results.length !== 0) { | |
// Do cool stuff | |
console.log(results); | |
} else { | |
console.log('No results found'); | |
} | |
} else { | |
console.log('Geocoder failed due to: ' + status); | |
} | |
}); | |
} | |
if (supportsLocation()) { | |
navigator.geolocation.getCurrentPosition(onSuccess, onError); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment