Botond Béres
Botond Béres

Reputation: 16683

Bad/poor GPS location accuracy on Android with React Native

I am working on a React Native app that works both on Android and iPhone. I have a feature where you can "share my current location". This works very well and accurately on iPhone but on Android, it only shows the correct city/locality however the actual location is far off from your street. For getting the location I use the https://github.com/Agontuk/react-native-geolocation-service library.

Here's the relevant code, I'm simply calling Geolocation.getCurrentPosition, not doing anything special. And I'm asking for high accuracy in options. Any ideas on how I can improve the accuracy on Android?

Edit: If I open Google Maps on the same Android phone, I get the accurate/correct location.

          Geolocation.getCurrentPosition(
            (position) => {
              // Do stuff with the position
            },
            (error) => {
              // See error code charts below.
              logError(
                new Error(
                  `Cannot get current location: ${error.code} ${error.message}`,
                ),
              );
            },
            {
              enableHighAccuracy: true,
              accuracy: {
                android: 'high',
                ios: 'bestForNavigation',
              },
              timeout: 15000,
              maximumAge: 10000,
              distanceFilter: 10,
            },
          );
        }
      },```

Upvotes: 1

Views: 1855

Answers (1)

Botond Béres
Botond Béres

Reputation: 16683

I figured out that the issue was that I did not have the ACCES_FINE_LOCATION permission in my AndroidManifest.xml. It's a bit confusing because this did not result in any actual error, it just did not give accurate location instead.

So just add this to the manifest file

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Upvotes: 2

Related Questions