I have the following script that is successfully sending geolocation information to my backend php script at 12 second intervals.
What I would now like to do, is to adapt the script so that it outputs the content returned by the php script back to the user, replacing any previously returned content (so only the latest content is shown).
<script>
var currPosition;
navigator.geolocation.getCurrentPosition(function(position) {
updatePosition(position);
setInterval(function(){
var lat = currPosition.coords.latitude;
var lon = currPosition.coords.longitude;
var sessionid = "<?php echo $sessionid; ?>";
jQuery.ajax({
type: "POST",
url: "live_trips.php",
data: 'lat='+lat+'&lon='+lon+'&sessionid='+sessionid,
cache: false
});
}, 12000);
}, errorCallback);
var watchID = navigator.geolocation.watchPosition(function(position) {
updatePosition(position);
});
function updatePosition( position ){
currPosition = position;
}
function errorCallback(error) {
var msg = "Can't get your location. ";
if (error.code == 1)
msg += "PERMISSION_DENIED";
else if (error.code == 2)
msg += "POSITION_UNAVAILABLE";
else if (error.code == 3)
msg += "TIMEOUT";
msg += ", msg = "+error.message;
alert(msg);
}
</script>