-
-
Save CamonZ/471593 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
// geo-location bridge | |
function getLocation(callback){ | |
if (getLocation.cache) return callback(getLocation.cache); | |
if (Modernizr.geolocation) { | |
var geocallback = function(position) { | |
callback(getLocation.cache = { | |
"lat": position.coords.latitude, | |
"lon": position.coords.longitude, | |
"obj": position | |
}) | |
}; | |
navigator.geolocation.getCurrentPosition(geocallback); | |
navigator.geolocation.watchCurrentPosition(geocallback); | |
} else { | |
$.getScript('//www.google.com/jsapi',function(){ | |
callback(getLocation.cache = { | |
"lat": google.loader.ClientLocation.latitude, | |
"lon": google.loader.ClientLocation.longitude, | |
"obj": google.loader.ClientLocation | |
}) | |
}); | |
} | |
} | |
// usage | |
getLocation(function(pos){ | |
console.log("I'm located at ",pos.lat,' and ',pos.lon); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment