Created
April 2, 2012 22:03
-
-
Save OndrejSlamecka/2287537 to your computer and use it in GitHub Desktop.
Google Maps v3 API useGeolocation
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
/* 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