react-native-geolocation-service icon indicating copy to clipboard operation
react-native-geolocation-service copied to clipboard

Sometimes gps is not turned off

Open roysG opened this issue 5 years ago • 1 comments

Your plugin works very well, but there are times that gps is not turn off. For fixing it I tried also to save all watches and cancel all the ids when gps is off.

Code: ----------(enable function)------------ const watchID = Geolocation.watchPosition( async (lastPosition) => { console.log('roy get location android', lastPosition); this.someFunc(lastPosition.coords); }, (error) => { }, { enableHighAccuracy: true, timeout: 10000, maximumAge: 0, distanceFilter: 0, interval: 500, fastestInterval: 100 }); watchesID.push(watchID); await AsyncStorage.setItem('watchesID', JSON.stringify(watchesID));

-------Disable Postion (disable function)------- Geolocation.stopObserving(); let watchesID = await AsyncStorage.getItem('watchesID'); watchesID = watchesID === null ? [] : JSON.parse(watchesID); watchesID.forEach(watchID => { Geolocation.clearWatch(watchID); }); await AsyncStorage.removeItem('watchesID');

My app is running in background even if user close the app from task manager.

roysG avatar Sep 19 '19 16:09 roysG

Sorry for the late reply, there's no need to use stopObserving. clearWatch calls stopObserving if there is not watchers left. You should check if all the watchers are being cleared properly or not.

Also if your app is running on background, then it'll always watch for location changes. You should stop it manually based on your business requirements.

Agontuk avatar Apr 27 '20 16:04 Agontuk