You need to make sure that you call the Geolocation.clearWatch () method with an identifier so that it resets the location.
See an example below:
Web / API / Geolocation.watchPosition
The Geolocation.watchPosition () method is used to register a handler function that will be called automatically every time the device position changes. You can also specify the error handling callback function.
This method returns the value of the hour identifier, which can be used to unregister the handler by passing it to Geolocation.clearWatch ().
Syntax
var id, target, option; function success(pos) { var crd = pos.coords; if (target.latitude === crd.latitude && target.longitude === crd.longitude) { console.log('Congratulation, you reach the target'); navigator.geolocation.clearWatch(id); } }; function error(err) { console.warn('ERROR(' + err.code + '): ' + err.message); }; target = { latitude : 0, longitude: 0, } options = { enableHighAccuracy: false, timeout: 5000, maximumAge: 0 }; id = navigator.geolocation.watchPosition(success, error, options);
You can also try wrapping the clear function as shown below. Also, by setting it to null, it will be updated.
// clear the watch that was started earlier // function clearWatch() { if (watchID != null) { navigator.geolocation.clearWatch(watchID); watchID = null; } }
SoftwareCarpenter
source share