Skip to content

Instantly share code, notes, and snippets.

@joeljunstrom
Created October 5, 2012 08:06
Show Gist options
  • Save joeljunstrom/3838685 to your computer and use it in GitHub Desktop.
Save joeljunstrom/3838685 to your computer and use it in GitHub Desktop.
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