Facing this issue and not able to find a solution for this.
My objective is to track the user's location every 30 seconds to 60 seconds with a foreground service running (with a notification) so that the user knows his location is being tracked.
The foreground service is working fine, I used '@supersami/rn-foreground-service'
npm packagae https://www.npmjs.com/package/@supersami/rn-foreground-service. the foreground task is running very consistently even from the app is killed or closed.
So I thought of adding the geolocation fetch inside this task to get the location of the device. I am using 'react-native-geolocation-service'
npm package https://www.npmjs.com/package/react-native-geolocation-service.
After probably 30-40 seconds of killing the app. The geolocation API stops fetching the location and starts throwing an error Location request timed out.
Why is this happening? And how can i stop this from happening?
Why do we have a timeout for fetching the GPS location? And with no timeout, the onError
callback function doesn't get called, below is the code.
ReactNativeForegroundService.add_task(
() => {
Geolocation.getCurrentPosition(
(position) => {
console.log(position);
},
(error) => {
// See error code charts below.
console.log(error.code, error.message);
},
{enableHighAccuracy: true, timeout: 1000, maximumAge: 10000},
);
},
{
delay: 100,
onLoop: true,
taskId: 'taskid',
onError: (e) => console.log('Error logging:', e),
},
);
My objective is to get the GPS coordinates with a foreground service running in any Android Device. Please help me out here, if I am doing anything wrong or missing out anything vital.
question from:
https://stackoverflow.com/questions/65902006/react-native-geolocation-without-timeout-in-foreground-service 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…