cordova-plugin-geolocation icon indicating copy to clipboard operation
cordova-plugin-geolocation copied to clipboard

Timeout on iOS after clearWatch

Open JimBacon opened this issue 7 years ago • 0 comments

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
  2. exec(win, fail, 'Geolocation', 'addWatch', [id, options.enableHighAccuracy]);
  3. The onSuccess callback following step 1 calls clearWatch
  4. The win callback following step 2 restarts the timeout
  5. 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.

JimBacon avatar Aug 31 '18 11:08 JimBacon