Geolocation fetch is taking too long
See original GitHub issueHello,
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:
- Created 3 years ago
- Reactions:8
- Comments:21 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub 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!