Skip to content

Instantly share code, notes, and snippets.

@OndrejSlamecka
Created April 2, 2012 22:03
Show Gist options
  • Save OndrejSlamecka/2287537 to your computer and use it in GitHub Desktop.
Save OndrejSlamecka/2287537 to your computer and use it in GitHub Desktop.
Google Maps v3 API useGeolocation
/* Ondrej Slamecka 2012 */
/**
* @param success Callback called on success
* @returns bool
*/
google.maps.Map.prototype.useGeolocation = function(success, failure)
{
if(typeof success === 'undefined')
return false;
var geolocator;
try {
if (typeof navigator.geolocation === 'undefined'){
geolocator = google.gears.factory.create('beta.geolocation');
} else {
geolocator = navigator.geolocation;
}
} catch(error) {
failure();
console.log('Unable to load geolocation service');
throw error;
return false;
}
if (geolocator) {
var self = this;
geolocator.getCurrentPosition(
function(position){
success(position);
},
function(error){
failure();
console.log('Unable to get current position from geolocation service');
throw error;
return false;
}
);
} else {
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment