react-native-geolocation-service: Enable enableHighAccuracy in iOS only returns position after timeout
With build 5.0 and enableHighAccuracy=true
the position on iOS devices is only returned after the timeout is reached. Im my case this is after 10 seconds. When I disable enableHighAccuracy it works fine. This is a new behaviour with build 5. Before it worked as expected.
This only happens on real devices. In the simulator it immediately returns the location.
I am using the following options for getCurrentPosition:
{
distanceFilter: 100,
enableHighAccuracy: true,
timeout: 10000,
maximumAge: 60 * 5 * 1000
}
I tested this on several iOS devices and the behaviour is the same.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 13
- Comments: 31 (12 by maintainers)
Went through
requestLocation
iOS docs which this library uses forgetCurrentPosition
. According to them, this function will try to get GPS data for the accuracy set. Under the hood enableHighAccuracy useskCLLocationAccuracyBest
which is the highest accuracy possible. GPS algorithms use lot of data to calculate GPS position like wifi, bluetooth, mobile signal and GPS. Hence calculating GPS location with accuracykCLLocationAccuracyBest
will vary from place to place.According to the docs it will return GPS location if it satisfies the desired accuracy or after timeout. Hence for your error cases it looks like the device is taking around 10 sec to get the desired accuracy, so this delay.
Earlier this library used to start a GPS continuous update request and will stop on first result and send the response in
getCurrentPosition
. This should have returned first location earlier, but this might not be of required accuracy. This is how continuous GPS location request works.So, you have two options to solve this problem,
enableHighAccuracy:false
(which will use like city level accuracy).There are other accuracy options in iOS native API, but that is not supported in this library.
kCLLocationAccuracyReduced
is supported only in iOS 14. For iOS < 14, should we fall back to usethreeKilometers
?@rayj10 you can use the master branch to try out
accuracy
option, it’s already implemented. API may change, so use it only to test the feature.setting maximumAge to
N
means for the nextN/1000
seconds if you request location, it’ll return the previous result.setting distanceFilter to
N
means it’ll notify location change only when user moves at leastN
meterv5.1.0 published with accuracy level support, doc has been updated.