question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Geolocation fetch is taking too long

See original GitHub issue

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

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
NoahFacecommented, Dec 22, 2020

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.

3reactions
thanhluantl2304commented, Jan 18, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Geolocation is so slow! what I'm doing wrong? - Stack Overflow
Check your mobile device's Location service mode. Make sure the accuracy is in High status on your devide. The High accuracy mode uses...
Read more >
Geolocation.getCurrentPosition() - Web APIs | MDN
A positive long value representing the maximum length of time (in milliseconds) the device is allowed to take in order to return a...
Read more >
Using JavaScript's Geolocation API - Spatial Times
The JavaScript Geolocation API 'provides access to geographical ... A request timeout can occur if the data takes too long to return.
Read more >
Geolocation: Displaying User or Device Position on Maps
This tutorial shows you how to display the geographic location of a user or device on a Google map, using your browser's HTML5...
Read more >
Xamarin.Essentials: Geolocation - Microsoft Learn
The Geolocation class provides APIs to retrieve the device's current geolocation coordinates. Get started. To start using this API, read the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found