Geolocation clearWatch() seems not to stop GPS tracking

When i start checking geolocation with navigator.geolocation.watchPosition() (cordova-plugin-geolocation is installed), and want to stop it, clearWatch() stops delivering geolocation information but the GPS symbol in the phone’s statusbar doesn’t disappear.

After closing the app, GPS symbol disappears.

Correct behaviour?
What about battery lifetime?

Is it just the symbol in the status bar or is GPS still activated and delivers new choords?

Thanks!

weird. If you’re not using crosswalk. (just compiling with cordova) then the gps behavior is determined and executed by the native browser of your mobile device.

More info about the device you’re running this would be helpful. also, did you try this on a different device just to see if you get the same behavior?

Thanks for replying!

Crosswalk is not being used.

Tested on

  • HTC One M7 with Android 4.4.4 (OmniRom)
  • Samsung Galaxy S3 Mini with Android 4.2.2

cordova.exec(null, null, "Geolocation", "stopLocation", []) doesn’t work either

Do you save the pointer object that it generates when you start it ?? ( in those examples i use a variable named watchId)

Here is how i turn it on

watchId = window.navigator.geolocation.watchPosition( watchSuccess, handleError, { maximumAge: 0, enableHighAccuracy: true } );

Here is how i turn it OFF

window.navigator.geolocation.clearWatch( watchId );

That’s the same way i implemented watchPosition() and clearWatch().

If you run clearWatch, does the geolocation-Symbol disappear from status bar?

clearWatch should remove GPS signal icon from status bar if something else is not actively using it. I had similar problems but can’t remember exactly. I think the thing was that several new watch position ID’s where created in some cases when you pause app (exit from app but not kill it) and start it again.
You probably have the same problem, check if you have several watch positon ids.

Just worked on this old issue today and fixed it.
It was my fault, my openlayers module created his own geolocation listener. So i had two of them but only killed one with clearWatch().
clearWatch() works as expected.