I have geolocation running in my app, followed examples described in docs. IOS version works fine, android however works only on non xiaomi devices. I tried on 2 xiamomi devices, and got Location request timed out error. While on samsung devices it works fine.
navigator.geolocation.getCurrentPosition(
(position) => {
let initialPosition = JSON.stringify(position);
console.log(initialPosition);
},
(error) => console.log(JSON.stringify(error)),
{enableHighAccuracy: Platform.OS != 'android', timeout: 2000, maximumAge: 2000 }
);
Need to find a way either provide reason why timed out, or just fix it.
Need to check permissions on some devices before requesting navigator.geolocation.getCurrentPosition(...):
Use https://github.com/lucasferreira/react-native-android-permissions or https://facebook.github.io/react-native/docs/permissionsandroid.html
Duplicated of #7495
Have same issue, too. Check permission is not enough. See my answer at https://github.com/facebook/react-native/issues/7495#issuecomment-287793663
Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!
If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:
If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.
For anyone else struggling with this issue on android, try removing the maximumAge: 2000 option parameter. This option was causing geolocation to either timeout or crash the app.
I'm running react-native 0.46.4 btw.
I am also struggling for the same issue. let me know if anybody have solution for this.
I am using RN 0.48
Has anybody find a solution for this ?
Duplicate #7495
when working with map:
For those of you who still are experiencing this issue, I was able to solve it by omitting the parameter _maxAge_, e.g. {enableHighAccuracy: true, timeout: 5000}).
At least I can confirm this with API level 23 and RN 0.51. I also used had
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
in the AndroidManifest.xml file.
About not using _maxAge_: a pull request mentions an issue with it (https://github.com/Clintal/react-native-picker/commit/320003e1dbf6ac03798b9f6842eaa4f1bf77c4eb)
{ enableHighAccuracy: false, timeout: 20000, maximumAge: 1000 },
Make "enableHighAccuracy: false" works for me
Guys....removing maximumAge solved the problem
@digvijayMobantica , setting enableHighAccuracy: false is strongly not encouraged
You can verify the permission before calling getCurrentPosition
if (Platform.OS === 'android') {
const granted = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION);
if (!granted) {
return;
}
}
...
EDIT : Actually just forgot to turn on the GPS option on my emulator -..-
Most helpful comment
For anyone else struggling with this issue on android, try removing the
maximumAge: 2000option parameter. This option was causing geolocation to either timeout or crash the app.I'm running react-native 0.46.4 btw.