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

PERMISSION_DENIED:1, POSITION_UNAVAILABLE: 2 Code : 2, Message: "No location provider available". in Android device

Open prajna-h opened this issue 4 years ago • 25 comments

Getting the below error { "PERMISSION_DENIED": 1, "POSITION_UNAVILABLE":2, "TIMEOUT": 3, "code" 2, "message": "No location provider available."}

Environment react-native-cli: 2.0.1 react-native: 0.62.2

@react-native-community/geolocation: ^2.0.2

buildToolsVersion = "28.0.3" minSdkVersion = 16 compileSdkVersion = 28 targetSdkVersion = 28 supportLibVersion = "27.1.1" googlePlayServicesAuthVersion = "17.0.0"

Android version - 10

prajna-h avatar Sep 03 '20 09:09 prajna-h

Try to enable your Location Permission on your Android Device.

Work for me. Thanks

andifirwansyah avatar Sep 05 '20 09:09 andifirwansyah

Hey andiwawank,

Yes, If I manually enable location, I will be able to fetch it through code. If the location is not enabled I will not be able to get the location. But it should invoke and turn on the location if its not enabled right?

Thanks.

On Sat, Sep 5, 2020, 2:35 PM andiwawank [email protected] wrote:

Try to enable your Location Permission on your Android Device.

Work for me. Thanks

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/react-native-community/react-native-geolocation/issues/120#issuecomment-687575473, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIWHSW7WUBMZQ6LIUT3G27DSEH5ODANCNFSM4QUSCBEQ .

prajna-h avatar Sep 06 '20 06:09 prajna-h

Hi @prajna-h

To request access to location, you can using PermissionsAndroid API and add the following line to your app's AndroidManifest.xml

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

useEffect(() => {
    const requestLocationPermission = async () => {
        try {
            const granted = await PermissionsAndroid.request(
                PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,{
                    'title': 'Location Access Required',
                    'message': 'This App needs to Access your location'
                }
            )
            if (granted === PermissionsAndroid.RESULTS.GRANTED) {
                //To Check, If Permission is granted
                setGrantedPermission(true)
                this._getCurrentLocation();
            } else {
                alert("Permission Denied");
            }
        } catch (err) {
                alert("err",err);
        }
    }
    requestLocationPermission();
}, [isGranted])

Thanks

andifirwansyah avatar Sep 07 '20 03:09 andifirwansyah

I am already using Permission Android. Still unable to get the location. :(

On Mon, Sep 7, 2020, 8:46 AM andiwawank [email protected] wrote:

Hi @prajna-h https://github.com/prajna-h

To request access to location, you can using PermissionsAndroid API https://reactnative.dev/docs/permissionsandroid and add the following line to your app's AndroidManifest.xml

useEffect(() => { const requestLocationPermission = async () => { try { const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,{ 'title': 'Location Access Required', 'message': 'This App needs to Access your location' } ) if (granted === PermissionsAndroid.RESULTS.GRANTED) { //To Check, If Permission is granted setGrantedPermission(true) this._getCurrentLocation(); } else { alert("Permission Denied"); } } catch (err) { alert("err",err); } } requestLocationPermission();}, [isGranted])

Thanks

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/react-native-community/react-native-geolocation/issues/120#issuecomment-688001903, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIWHSW6IJQH72JZ4RKJAITLSERGBTANCNFSM4QUSCBEQ .

prajna-h avatar Sep 07 '20 07:09 prajna-h

@prajna-h did you find a solution?

hasnabbas avatar Sep 13 '20 16:09 hasnabbas

I was having the same issue 5 min ago, just add this to your android/app/src/main/AndroidManifest.xml <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

fvilar avatar Sep 13 '20 21:09 fvilar

I enable GPS and added this
"android.permission.ACCESS_FINE_LOCATION" in manifest and requested for permission and still i am getting this { "PERMISSION_DENIED": 1, "POSITION_UNAVILABLE":2, "TIMEOUT": 3, "code" 2, "message": "No location provider available."}

react: 16.13.1 react-native: 0.6.3.0

@react-native-community/geolocation: ^2.0.2

webhibegit avatar Sep 16 '20 07:09 webhibegit

Location is not working on these devices where it's working other devices as well .

  1. hawaii p8 lite android Version 5
  2. hawaii y7 prime

Permission

React Native and lib version "@react-native-community/geolocation": "^2.0.2", "react-native": "0.62.2",

ZainaliSyed avatar Sep 19 '20 18:09 ZainaliSyed

same issue android device have already permission 'android.permission.ACCESS_FINE_LOCATION' but getting the same timeout error

JameelNazir avatar Sep 21 '20 07:09 JameelNazir

Same issue on techno

JameelNazir avatar Sep 21 '20 07:09 JameelNazir

The enabled location from settings and it is working fine

JameelNazir avatar Sep 21 '20 08:09 JameelNazir

same issue android device have already permission 'android.permission.ACCESS_FINE_LOCATION'

Solution It's working on all devices with LIBRARY : react-native-geolocation-service

DONOT USE : @react-native-community/geolocation

ZainaliSyed avatar Sep 21 '20 08:09 ZainaliSyed

The problem while using @react-native-community/geolocation is that if the GPS is not turned on manually it won't as for it (only ask for location permission not to turn on the GPS) and when we as enable it manually it says location request timeout. While using react-native-geolocation-service it won't ask for location permission which should be the first step, else part is working fine in this library.

Any help will be appreciated.

raazatul7 avatar Oct 11 '20 07:10 raazatul7

Google stopped supporting android 5 in 2017 Google stopped support androind 6 in 2019

itsonlycode avatar Oct 14 '20 00:10 itsonlycode

same issue android device have already permission 'android.permission.ACCESS_FINE_LOCATION'

Solution It's working on all devices with LIBRARY : react-native-geolocation-service

DONOT USE : @react-native-community/geolocation

You are right bro. Its already written in MD file. We should use newer react-native-geolocation-service

yalcinozer avatar Oct 16 '20 07:10 yalcinozer

I was also getting this same error. I realised that my Phone GPS was OFF. Once i turned it ON the error went away and it returned my current location.

abhishrek avatar Dec 11 '20 12:12 abhishrek

Solution It's working on all devices with LIBRARY : react-native-geolocation-service

@ZainaliSyed -- terrible advice.

Any android phone that doesn't have google play (i.e. any phone in China) will not work with react-native-geolocation-service, so no it doesn't work on all devices.

ortonomy avatar Mar 10 '21 06:03 ortonomy

The enabled location from settings and it is working fine

what if the user turned off the location services and granted the permission yes, then they will get an error message

sumitsk1 avatar Mar 26 '21 12:03 sumitsk1

please turn on the location on your device and try it out after that.

mafei-dev avatar Apr 06 '21 11:04 mafei-dev

Just use what @ZainaliSyed suggest react-native-geolocation-service

bsor-dev avatar Apr 26 '21 04:04 bsor-dev

@rosnaib11 -- do you even read responses. That library uses google play services and device without google play services will still fail...

ortonomy avatar Apr 26 '21 06:04 ortonomy

Switch to react-native-geolocation-service

sumitsk1 avatar Jan 06 '22 14:01 sumitsk1

Please stop suggesting react-native-geolocation-service as blanket advice - there are plenty of versions of Android that don't contain Google's services and this won't work! Please be aware of that.

ortonomy avatar Jan 07 '22 01:01 ortonomy

I have same problem with you in android device. there are 2 suggestion. change to react-native-geolocation-service or use react-native-android-location-enabler to ask user to enable the gps. i use the second suggestion, i use react-native-android-location-enabler version 1.2.2.

(nb: i am still looking solution without adding new library)

here is my code (it's better to give some condition before ask user to enable the gps)


...
import RNAndroidLocationEnabler from 'react-native-android-location-enabler';
...

const _geolocation = () => {
  Geolocation.getCurrentPosition(
    async position => {
      setLatitude(position.coords.latitude);
      setLongitude(position.coords.longitude);
    },
    async error => {
      console.log(error.message);
      if (Platform.OS === 'android') {
        await _enableGPS();
      }
    },
    {
      enableHighAccuracy: false,
      timeout: 30000,
      maximumAge: 50000
    }
  );
};

const _enableGPS = async () => {
  try {
    await RNAndroidLocationEnabler.promptForEnableLocationIfNeeded({
      interval: 10000,
      fastInterval: 5000
    });
    
    // do some action after the gps has been activated by the user
    
  } catch (error) {
    console.log(error);
  }
};

enabler

i hope this can help u

sipamungkas avatar Jan 26 '22 10:01 sipamungkas

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:installDebug'.

java.util.concurrent.ExecutionException: com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException: Unknown failure: Exception occurred while executing 'install': java.lang.IllegalArgumentException: Error: ==== whenever i install new dependency in my project i got this error import RNAndroidLocationEnabler from 'react-native-android-location-enabler'; i could use this enabler and I am using react native 0.70 version and even cant use npm install react-native-permissions because error shows cant read dependency

rahulsoni27 avatar Apr 28 '23 11:04 rahulsoni27

If you experience this error, you might want to try the Play Services provider https://github.com/michalchudziak/react-native-geolocation#setrnconfiguration (which is the API that's used in the react-native-geolocation-service library). Alternatively I'll welcome any contribution solving the GPS permission issue mentioned in this thread.

michalchudziak avatar May 30 '23 10:05 michalchudziak

I have same problem with you in android device. there are 2 suggestion. change to react-native-geolocation-service or use react-native-android-location-enabler to ask user to enable the gps. i use the second suggestion, i use react-native-android-location-enabler version 1.2.2.

(nb: i am still looking solution without adding new library)

here is my code (it's better to give some condition before ask user to enable the gps)


...
import RNAndroidLocationEnabler from 'react-native-android-location-enabler';
...

const _geolocation = () => {
  Geolocation.getCurrentPosition(
    async position => {
      setLatitude(position.coords.latitude);
      setLongitude(position.coords.longitude);
    },
    async error => {
      console.log(error.message);
      if (Platform.OS === 'android') {
        await _enableGPS();
      }
    },
    {
      enableHighAccuracy: false,
      timeout: 30000,
      maximumAge: 50000
    }
  );
};

const _enableGPS = async () => {
  try {
    await RNAndroidLocationEnabler.promptForEnableLocationIfNeeded({
      interval: 10000,
      fastInterval: 5000
    });
    
    // do some action after the gps has been activated by the user
    
  } catch (error) {
    console.log(error);
  }
};

enabler

i hope this can help u

Thank you @sipamungkas

Prince-AppsTango avatar Mar 12 '24 12:03 Prince-AppsTango