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

Android 9 - `getCurrentPosition` and `requestAuthorization` always execute fail callback on first run

Open vozaldi opened this issue 3 years ago • 5 comments
trafficstars

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

  1. Upgrade from 2.1.0 to 3.0.2
  2. Clear storage data & permissions in app setting
  3. Launch the app
  4. Location permission request pop up and select "Allow"
  5. 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 });
};

vozaldi avatar Oct 31 '22 05:10 vozaldi

Can you provide a minimal repro project?

michalchudziak avatar Nov 07 '22 18:11 michalchudziak

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.

vozaldi avatar Nov 10 '22 08:11 vozaldi

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};
      }

phinguyen avatar Dec 13 '22 06:12 phinguyen

Same error, any solution?

KayyDhex avatar Dec 29 '22 01:12 KayyDhex

same issue do anyone found a solution ?

Shaka912 avatar Jul 16 '23 20:07 Shaka912