getCurrentPosition: cached location retrieved when enabling location in app background mode and moving back to app
Hi!
I have trouble with getting up-to-date location, when enabling location in background and going back to the app. I have screen that shows nearby location, the flow is:
- Set your current location to some point, i. e Paris
- Go to the app and enable location
- Quit app and disable location in settings
- Set your current location to different point, i. e London
- Go to the app again
- Since user has previously denied location, popup to enable location will be shown
- Go to settings and enable location (app is in background state at this step)
- Return to the app and for first 3-5 sec location returned is old one/cached one (i. e not London, but Paris set on the first step)
handleAppStateChange = (nextAppState: string): void => {
if (
this.state.appState.match(/inactive|background/) &&
nextAppState === "active"
) {
Geolocation.getCurrentPosition(
(position) => {
console.log(position)
},
(error) => {
console.log(error)
},
{
maximumAge: 0,
timeout: isIOS ? 100 : 0
}
)
}
}
Tried both on iOS and Android, with/without maximumAge set to 0, different timeout options. watchPosition has the same issue.
As I see from the source code for iOS and Android it should force to retrieve the location.
However I can't get it work, it shows the cached location and only after some time a new correct one, is there any workaround for that case?
Thanks for providing detailed steps, I'll see if I can reproduce this on my end and provide a fix if possible. As a workaround, you can use watchPosition and get the latest location by checking the timestamp.
v5.3.0-beta.4 released, check if it solves your issue.