Skip to content

Instantly share code, notes, and snippets.

Forked from paulirish/gist:366184
Created July 23, 2013 19:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
// geo-location shim
// currentely only serves lat/long
// depends on jQuery
// doublecheck the ClientLocation results because it may returning null results
if (geolocation) return;
var cache;
geolocation = window.navigator.geolocation = {};
geolocation.getCurrentPosition = function(callback){
if (cache) callback(cache);
// sometimes ClientLocation comes back null
if (google.loader.ClientLocation) {
cache = {
coords : {
"latitude": google.loader.ClientLocation.latitude,
"longitude": google.loader.ClientLocation.longitude
geolocation.watchPosition = geolocation.getCurrentPosition;
// usage
console.log("I'm located at ",pos.coords.latitude,' and ',pos.coords.longitude);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment