react-native-geolocation: Not permission (PERMISSION_DENIED) getCurrentPosition()

I’m having a permission error when picking up the user’s location.

{TIMEOUT: 3, POSITION_UNAVAILABLE: 2, PERMISSION_DENIED: 1, message: “Location request timed out”, code: 3}

My code:

componentDidMount() {
    Geolocation.getCurrentPosition(info => console.log(info));
  }

android.manifest:

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

Does anyone know what else it can be?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 4
  • Comments: 17

Most upvoted comments

It’s likely that you need to pass in some options to tell the device that you want to wake up the GPS receiver and actually get the fresh location. It must be that the phone hadn’t done that since it was turned on and therefore didn’t have a cached location to give you.

When we add support for the Fused Location Provider this should be improved as well.

I will mark this as resolved now. Let us know if you have further issues.

After an update mine worked. I’m getting the geolocation with this code:

import Geolocation from '@react-native-community/geolocation';

  getLocationUser = async () => {
    await Geolocation.getCurrentPosition(
      position => {
        const {latitude, longitude} = position.coords;
        this.setState({
          region: {
            longitude: longitude,
            latitude: latitude,
            latitudeDelta: 0.029213524352655895,
            longitudeDelta: (width / height) * 0.029213524352655895,
          }
        });
      },
      error => {
         console.log(error);
      },
    );
  };

@espipj @ptkpyitheim

Ok, thanks. Can you check that you are able to get a location if you open another app like Google Maps? What happens if you reopen the app after getting a location there? Does it work if you instead subscribe for location updates instead of just getting a single one?

@ldfxavier still times out/rejects for me, using exactly the same piece of code and asking for permission as stated on the readme and RN Docs…

Hey, I’m still getting this error. I think this shouldn’t be marked as resolved for now as there’s still not an elegant way to do it afaik. For me opening GMaps right before doesn’t work either…

Any ideas @ldfxavier ?

I’m testing on the emulator, but I tested it on real and the error happens.