cordova-plugin-geolocation
cordova-plugin-geolocation copied to clipboard
Timeout on iOS after clearWatch
iOS 11.4.1
I experience a timeout error after calling watchPosition and then calling clearWatch in the first success callback.
Example code would be some thing like
var count = 0
var watchID = navigator.geolocation.watchPosition(onSuccess, onError, { enableHighAccuracy: true });
var onSuccess= function (position) {
if (count === 0) {
navigator.geolocation.clearWatch(watchID);
}
count ++;
}
function onError(error) {
console.log('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
What I believe is happening is
watchPositioncallsgeolocation.getCurrentPositionfollowed byexec(win, fail, 'Geolocation', 'addWatch', [id, options.enableHighAccuracy]);- The
onSuccesscallback following step 1 callsclearWatch - The
wincallback following step 2 restarts the timeout - The timeout is hit because the geolocation was stopped in step 3
This was unexpected behaviour which I only figured out by looking at the source code of the plugin. I could easily resolve the problem by calling clearWatch a second time but it would be nicer for the plugin to handle this.