Skip to content

Instantly share code, notes, and snippets.

@jamesflorentino
Last active December 17, 2015 19:29
Show Gist options
  • Save jamesflorentino/5660633 to your computer and use it in GitHub Desktop.
Save jamesflorentino/5660633 to your computer and use it in GitHub Desktop.
//To get the GPS coordinate from the mobile browser:
navigator.geolocation.getCurrentPosition(function(location) {
// location.coords.longitude;
// location.coords.latitude;
});
//To let the server receive data, you'll need to create a service that will handle your json data.
//e.g. in node.js/express
app.put('api/location', function(req, res) {
// req.body.location;
// save coordinates to db/datastore
});
// Now that you have a RESTful service that handles data, you can now try to push data to the server every once in a while.
function updatePosition(location) {
var data = { x: location.coords.longitude, y: location.coords.latitude };
$.ajax({type: 'put', url: '/api/location', data: data, success: updateServer });
}
function updateServer() {
setTimeout(function() {
navigator.geolocation.getCurrentPosition(updatePosition);
}, 1000);
}
updateServer();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment