react-native-geolocation-service icon indicating copy to clipboard operation
react-native-geolocation-service copied to clipboard

getCurrentPosition always gets timeout error on Xiaomi && Huawei phone

Open ghost opened this issue 3 years ago • 6 comments

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);
  }

ghost avatar Jun 04 '21 02:06 ghost

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.

Agontuk avatar Jun 25 '21 12:06 Agontuk

I have the same issue. 😢

ozturkilgim avatar Apr 06 '22 15:04 ozturkilgim

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

dmic89 avatar Apr 11 '22 10:04 dmic89

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

bardliu avatar May 26 '22 06:05 bardliu

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

yylingsj avatar Oct 04 '22 05:10 yylingsj

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

efstathiosntonas avatar Dec 08 '22 16:12 efstathiosntonas