Agontuk / react-native-geolocation-service

React native geolocation service for iOS and android
https://www.npmjs.com/package/react-native-geolocation-service
MIT License
1.6k stars 291 forks source link

getCurrentPosition always gets timeout error on Xiaomi && Huawei phone #279

Open ghost opened 3 years ago

ghost commented 3 years ago

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);
  }
Agontuk commented 3 years ago

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.

ozturkilgim commented 2 years ago

I have the same issue. 😢

dmic89 commented 2 years ago

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

bardliu commented 2 years ago

the default getCurrentPosition method is andorid native method if ur phone does not have gms. u need to implement LocationProvider for hms like this: image

yylingsj commented 1 year ago

Did you fix it finally?I have the same issue.

efstathiosntonas commented 1 year ago

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