I have the following code with which I can obtain the coordinates of a telephone every 15 seconds.
The problem is that if the phone is blocked, the setInterval function stops working and it does not save the coordinates until after unlocking the phone.
function setGeolocation() {
var geolocation = window.navigator.geolocation.watchPosition(
function ( position ) {
var location=new google.maps.LatLng(position.coords.latitude,position.coords.longitude)
coordenadasRuta.push(location);
},
function () { /*error*/ }, {
maximumAge: 250,
enableHighAccuracy: true
}
);
window.setTimeout( function () {
window.navigator.geolocation.clearWatch( geolocation )
},
5000
);
};
setGeolocation();
window.setInterval( function () {
setGeolocation();
}, 15000);
Those coordinates then I save them to create a PolyLine so if it crashes it does not save my route correctly.
Do you have any idea why this happens?