Last active
December 17, 2015 19:29
-
-
Save jamesflorentino/5660633 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//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