react-native-geolocation: Code : 2, Message: "unable to retrieve location", PERMISSION_DENIED:1,POSITION_UNAVAILABLE: 2. in IOS

Environment

Platforms

Versions

  • Android:
  • iOS:
  • react-native-geolocation:
  • react-native:
  • react:

Description

Code : 2, Message: “unable to retrieve location”, PERMISSION_DENIED:1,POSITION_UNAVAILABLE: 2. in IOS simulator

Reproducible Demo

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 26
  • Comments: 38

Most upvoted comments

Click your simulator then Select Features > Location > Custom Location

same problem on real ios device

{"code":3,"message":"Unable to fetch location within 30.0s.","PERMISSION_DENIED":1,"POSITION_UNAVAILABLE":2,"TIMEOUT":3} I have been getting this on ios, although it still gets the position

@goodryanboy answer solved for me.

Click your simulator then Select Features > Location > Custom Location

please turn on gps or location 👍

same problem on real android device

any solution?, i have same problem on real android device

Try the following

return new Promise(resolve => {
    Geolocation.getCurrentPosition(
      position => {
        resolve(position);
      },
      err => resolve(err),
      {
        enableHighAccuracy: true,
        timeout: 15000,
        maximumAge: 10000,
      }
    );
  });

info.plist

NSLocationWhenInUseUsageDescription
NSLocationAlwaysUsageDescription
NSLocationAlwaysAndWhenInUseUsageDescription

AndroidManifest.xml

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

same problem on android device (not simulator)

so this problem is just on simulator?

  1. hawaii

SOLUTION

My location permission is working on every device

DONOT USE @react-native-community/geolocation

I simply use react-native-geolocation-service and it start working on every device of android

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

USE Library

https://github.com/Agontuk/react-native-geolocation-service

I am receiving this error on Android API 28 only. It works on API 29. Any idea why?

{"PERMISSION_DENIED": 1, "POSITION_UNAVAILABLE": 2, "TIMEOUT": 3, "code": 3, "message": "Location req
uest timed out"}

same issue with ios!