react-native-geolocation-service
react-native-geolocation-service copied to clipboard
Sometimes gps is not turned off
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.
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.