apache / apache/cordova-plugin-geolocation
Timeout on iOS after clearWatch
- Dominant language
- JavaScript
- Stars
- 646
- Forks
- 654
- PR merge metrics
- No merged PRs in 30d
Description
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
1. `watchPosition `calls `geolocation.getCurrentPosition` followed by
1. `exec(win, fail, 'Geolocation', 'addWatch', [id, options.enableHighAccuracy]);`
1. The `onSuccess `callback following step 1 calls `clearWatch`
1. The `win `callback following step 2 restarts the timeout
1. 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.
Contributor guide
Assessment
This issue has not been assessed yet.