react-native-geolocation: Function getCurrentPosition always returns timeout error on Android
Platforms
Android
Versions
- Android: 9
- react-native-geolocation: 1.4.2
- react-native: 0.61.1
- react: 16.9.0
- enableHermes: true
Description
Function Geolocation.getCurrentPosition
always returns error on Android
Location request timed out
{ "PERMISSION_DENIED": 1, "POSITION_UNAVAILABLE": 2, "TIMEOUT": 3, "code": 3, "message": "Location request timed out" }
I’ve tried to add timeout
and maximumAge
options but it doesn’t help me.
return new Promise(resolve => {
Geolocation.getCurrentPosition(
position => {
const { latitude, longitude } = position.coords;
resolve({ latitude, longitude });
},
err => resolve(err),
{
enableHighAccuracy: true,
timeout: 100,
maximumAge: 0,
}
);
});
Reproducible Demo
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 30
- Comments: 29
~Getting same issue after upgrading to react native 0.61. Not passing any configuration, simply calling
Geolocation.getCurrentPosition((info): void => { /* do something*/ });
~Update: Added
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
to theAndroidManifest.xml
and the issue went away 👍It’s probably because you have enableHighAccuracy set to true. When you’re in a building, the phone fails to accurately locate you and times out. What I did is:
Remove completely maximumAge param. It worked for me.
@yurii-oliiarnyk https://github.com/Agontuk/react-native-geolocation-service solves problem, change youre library
@hugopretorius914 thanks man, that helped me! But I didn’t do exactly what you said.
What I noticed is when I set this way below, it doesn’t work at all:
But if I set this way, it works!
This way works as well, like you said:
I don’t know why it’s working this way, but it works! I hope this can help somebody else.
By the way, I’m not using this lib, instead the one I have installed in my project is: https://github.com/Agontuk/react-native-geolocation-service
“react-native-geolocation-service”: ^5.1.1 “react”: “17.0.1”, “react-native”: “0.63.4”, Windows 10
I am also getting this error lately. I am using the following code:
@espipj there is problem with geolocation when u testing on some mobile phones, im getting(as mentioned above) permission denied error, but not in all mobile phones
{ “PERMISSION_DENIED”: 1, “POSITION_UNAVAILABLE”: 2, “TIMEOUT”: 3, “code”: 3, “message”: “Location request timed out” }
I’m getting same issue if I set
maximumAge
with react native version0.61.2
Getting the same error after upgrading to sdk 28
Getting the same error, is there another plugin that works better?
I’m facing same issue with my physical device. Works fine in emulator.
edit: i applied @espipj 's suggestion and its working now.
Hey guys, I have also received this issue lately. When you add a timeout in the config like …,{timeout: 10000} you WILL receive this error just ten seconds later. I thought it would give it more time to return successfully but no…
Same error here! I suggest to use https://github.com/Agontuk/react-native-geolocation-service which uses react-native-geolocation under the hood on iOS but works flawlessly on Android. 😄 @azhaubassar
The solution of @Temirtator works for me. Thanks!
My problem is similar to some extent. I have set the enableHighAccuracy to True. Sometimes it works fine but other times it returns Request Time Out response. I have increased the timeout limit to 150000 ms and maximumAge to 0, I have also added the FIN_Location permission in android manifest file. I think either the API is unstable or the surrounding factor is the issue. If i set the high accuracy to false then accuracy drops.
is there any solution for this case?
I have the same error, any solutions? 😦