react-native-geolocation-service
react-native-geolocation-service copied to clipboard
getCurrentPosition always gets timeout error on Xiaomi && Huawei phone
It always returns error_code=3, error_message="Location request timed out". It works in simulator, but not in real phone (Xiaomi and Huawei).
code:
Geolocation.getCurrentPosition(
(position) => {
console.log(position);
},
(error) => {
// See error code charts below.
console.log(error.code, error.message);
},
{ timeout: 5000, maximumAge: 10000, enableHighAccuracy: false, distanceFilter: 0 }
);
My intuition is that google play service is not supported in China. So, I changed locationProvider to non-google provider manually (as shown below). However, still timeout error.
private LocationProvider createLocationProvider() {
ReactApplicationContext context = getContext();
// if (LocationUtils.isGooglePlayServicesAvailable(context)) {
// return new FusedLocationProvider(context);
// }
return new LocationManagerProvider(context);
}
Not related to xiaomi/huawei, my redmi note 3 works fine. It's most probably a device specific issue, or might be an area with low gps signal. You can remove timeout option and see how long it takes to get a location fix.
I have the same issue. 😢
Had the same issue. I fixed it by setting android accuracy to "balanced". But I don't know if this is the right solution.
accuracy: { android: "balanced", ... },
But to be able to test it on the simulator I had to change it to "high" again. I got this workaround from GH-296
the default getCurrentPosition method is andorid native method if ur phone does not have gms.
u need to implement LocationProvider for hms like this:
Did you fix it finally?I have the same issue.
cross posting this here just in case someone wants to test this possible fix: https://github.com/Agontuk/react-native-geolocation-service/issues/174#issuecomment-1343015525