react-native-geolocation-service: Geolocation fetch is taking too long

Hello,

Thanks for the library. I am using the package as follows and the geolocation of the device takes almost half a minute to be fetched. Is this the normal behavior and is there anything I can do?

  Geolocation.getCurrentPosition(
            (position) => {
                const latitude = position.coords.latitude
                const longitude = position.coords.longitude
                store.dispatch(setUserCoordinates(latitude, longitude))
            },
            (error) => {
                return;
            },
            { enableHighAccuracy: true, maximumAge: 10000, 0 }
        )

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 8
  • Comments: 21 (4 by maintainers)

Commits related to this issue

Most upvoted comments

You may well be correct. However, the practical issue is that the way the code is written currently, it nearly always takes 10 seconds to get a position read on iOS (in my experience), which is impractical for many applications. A lot of people have tried to switch to this package because the alternative was slow on Android. This package currently has the opposite issue in that it’s too slow on iOS to be useable. I don’t think its practical to suggest to people they should use watchPosition/clearWatch to get a one time read when that’s exactly what getCurrentPosition is supposed to do, and those using the package should not need to have an understanding of how the package works internally (nor do we want them coding in different ways on Android vs. iOS).

I have three ideas:

A. Maybe the getCurrentPosition code should: - Use the current logic if enableHighAccuracy = true. - Use the logic I have suggested if enableHighAccuracy = false.

B. Another alternative approach might be to call startUpdatingLocation but not accept the first reading that comes back. Rather, take the last reading that you have in say 2 or 3 seconds (or make this time configurable).

C. There is already a maximumAge option. So, you could call startUpdatingLocation() but honour the maximumAge setting to avoid returning stale locations (rather than relying on a maximum wait time as in B).

If it really does typically take 10 secs to get an accurate enough GPS read on iOS, then only A is going to cut it.

when will this fix be released? I’m still waiting for it!

Master branch is now updated with the fix, please try & see if it works for you. I’ll release a new version soon.

I wanted to see if there’s any other solution, but seems like it’ll be good enough for now.

Master branch is now updated with the fix, please try & see if it works for you. I’ll release a new version soon.

I wanted to see if there’s any other solution, but seems like it’ll be good enough for now.

i have tested the master branch and it works for me, when will you start a new release? I can’t wait for it.

I am using this library from last 2 years. It is great. Thanks.

This library was working well up to version 4.0.2. getCurrentPosition returns location within 1 second.

I updated it to V5.1.1 on noticing below issue on IOS 14.2 and 14.3: https://github.com/Agontuk/react-native-geolocation-service/issues/230

Now, the latest version 5.1.1 returns location after 10 seconds.

Here are more details:

  1. Library version 5.1.1
  2. enableHighAccuracy: true
  3. Platform : IOS
  4. Method: getCurrentPosition

This long delay is noticed on V5.0.0+.

Do you know what is changed from V4.0.2 to 5.0.0 that introduced this issue.

Are you going to fix getCurrentPosition for long delay issue.

This is breaking IOS app and is a blocker.

The local fixes I suggested definitely fixed the 10 second issue for me on IOS, and I have not found any side effects. Make sure the module is being rebuilt - perhaps insert some logging. My settings are as follows:

    Geolocation.getCurrentPosition(
          (position) => {
            ....
            }
          },
          (error) => {
           ......
          },
          {enableHighAccuracy: true, timeout: 12000, maximumAge: 30000, showLocationDialog: true}
        );

HTH.

Hi @Agontuk thanks for your work.

In my case, I need the most accurate location possible. On android I get the result quickly, but on ios it takes 10s, sometimes more, to get the position.

I tested the geolocation package and the opposite happens. On ios I get the result instantly but on android, it takes longer…

PS: I upgraded to the latest version 5.1.1 and it still taking too long.

Thanks