I am experiencing issues with the GPS coordinates being stuck when using geolocation in a Progressive Web App (PWA). Sometimes, the coordinates get stuck at the previous location, even if the user has moved since then.
I suspect that this is due to the GPS tracking the last known location rather than updating to the current one.
Is there a way to refresh the GPS and only send data once it has a valid, updated connection?
Below is the code for the geolocation:
if ("geolocation" in navigator && navigator.geolocation != null) {
try {
navigator.geolocation.getCurrentPosition(position => {
//if geolocation has a valid connection
console.log(position);
$('#geolocation_form_latitude').val(position.coords.latitude);
$('#geolocation_form_longitude').val(position.coords.longitude);
$('#geolocation_form').submit();
}, error => {
$('#geolocation_form').submit();
})
}
catch (e) {
$('#geolocation_form').submit();
}
}