I'm working on a bit of code to save the user's current GPS coordinates to a mysql table every 5 minutes. I'm familiar with PHP and learning javascript at the moment so I need some assistance with the javascript portion of the code.
My current code sample will get the user's GPS position every 5 seconds and set it as the javascript variable lat and lon. The javascript function runs every 5 seconds for now, but will eventually be updated to run every 5 minutes.
What do I need to add to the code to insert the lat and lon variables into a mysql table each time the function is called?
Here is my current code example:
<!DOCTYPE html>
<html>
<body>
<p>Get GPS Location Every 5 seconds</p>
<p id="coordinates"></p>
<body onload="getLocation()">
<script>
var x = document.getElementById("coordinates");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
setTimeout(getLocation, 5000);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
</script>
</body>
</html>