Skip to content

Instantly share code, notes, and snippets.

@jcready
Created May 30, 2013 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcready/5679876 to your computer and use it in GitHub Desktop.
Save jcready/5679876 to your computer and use it in GitHub Desktop.
navigator.geolocation.watchPosition(function(g){
if (g.coords.latitude === null && g.coords.longitude === null) return;
var c = g.coords, l = { acc: c.accuracy };
if (c.latitude !== null) l.lat = ~~(c.latitude*10000)/10000;
if (c.longitude !== null)l.long = ~~(c.longitude*10000)/10000;
if (c.speed !== null) l.speed = c.speed;
if (c.heading !== null && !isNaN(c.heading)) l.dir = c.heading;
if (c.altitude) { l.alt = c.altitude; l.altacc = c.altitudeAccuracy }
console.log(l);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment