react-native-geolocation
react-native-geolocation copied to clipboard
Android 9 - `getCurrentPosition` and `requestAuthorization` always execute fail callback on first run
Environment
LG V30 (Android 9)
Platforms
Android
Versions
- Android: 9
- iOS:
- react-native-geolocation: 3.0.3
- react-native: 0.70.4
- react: 18.1.0
Description
Upgraded Geolocation from 2.1.0 to 3.0.2 without modifying my code.
Both methods getCurrentPosition and requestAuthorization is returning a fail instead of success whenever I selected "Allow" on the permission popup.
Reproducible Demo
- Upgrade from 2.1.0 to 3.0.2
- Clear storage data & permissions in app setting
- Launch the app
- Location permission request pop up and select "Allow"
- Instead of success callback, the fail callback is executed.
const handleLocationRequest = () => {
Geolocation.getCurrentPosition(() => {
console.log("Position granted");
}, ({ code }) => {
console.log("Position not granted. Code:", code);
}, { timeout: 10000 });
};
Can you provide a minimal repro project?
Hi @michalchudziak
Here's the repro link https://github.com/vozaldi/repro-rngeolocation-209
I'm using Android 9 emulator (API 28).
At first I installed v2.1.0 and tested Geolocation.getCurrentPosition() method, which runs as expected. And then I upgraded to latest version (v3.0.3) but the issue I explained above still occurring.
Video in Google Drive.
i'm workaround by convert Geolocation to async/await
const getCurrentPosition = () =>
new Promise((resolve, error) =>
Geolocation.getCurrentPosition(resolve, error, {
timeout: 20000,
maximumAge: 240000,
enableHighAccuracy: false,
}),
);
try {
const data = await getCurrentPosition();
return {status: true, data};
} catch (error) {
return {status: false, data: null};
}
Same error, any solution?
same issue do anyone found a solution ?