react-native-geolocation
react-native-geolocation copied to clipboard
PERMISSION_DENIED:1, POSITION_UNAVAILABLE: 2 Code : 2, Message: "No location provider available". in Android device
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
Try to enable your Location Permission on your Android Device.
Work for me. Thanks
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 .
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
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 did you find a solution?
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" />
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
Location is not working on these devices where it's working other devices as well .
- hawaii p8 lite android Version 5
- hawaii y7 prime
Permission
React Native and lib version "@react-native-community/geolocation": "^2.0.2", "react-native": "0.62.2",
same issue android device have already permission 'android.permission.ACCESS_FINE_LOCATION' but getting the same timeout error
Same issue on techno
The enabled location from settings and it is working fine
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
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.
Google stopped supporting android 5 in 2017 Google stopped support androind 6 in 2019
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
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.
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.
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
please turn on the location on your device and try it out after that.
Just use what @ZainaliSyed suggest react-native-geolocation-service
@rosnaib11 -- do you even read responses. That library uses google play services and device without google play services will still fail...
Switch to react-native-geolocation-service
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.
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);
}
};
i hope this can help u
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
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.
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); } };
i hope this can help u
Thank you @sipamungkas