Skip to content

Instantly share code, notes, and snippets.

@max-power
Created May 3, 2012 06:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save max-power/2583676 to your computer and use it in GitHub Desktop.
Save max-power/2583676 to your computer and use it in GitHub Desktop.
HTML5 Geolocation Polyfill
// requires jquery.js, tested with reqwest.js with jquery compat mode
// uses http://geoplugin.net/json.gp
// lowercase arguments are just string placeholder
// F = Function placeholder
// Z = Cache placeholder
;(function(N,g,c,x,y,u,j,F,Z) {
F=function(s,e){Z?s(Z):$.ajax({url:'//'+u+'.net/'+j+'.gp',dataType:j+'p',jsonp:j+'callback',error:e,success:function(R){Z={};Z[c]={};Z[c][x]=R[u+'_'+x];Z[c][y]=R[u+'_'+y];s(Z)}})}
N[g]=N[g]||{getCurrentPosition:F,watchPosition:F,clearWatch:function(){Z=undefined}}
})(navigator,'geolocation','coords','latitude','longitude','geoplugin','json');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment