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.

Enable enableHighAccuracy in iOS only returns position after timeout

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:13
  • Comments:31 (12 by maintainers)

github_iconTop GitHub Comments

5reactions
ravirajn22commented, Sep 24, 2020

Went through requestLocation iOS docs which this library uses for getCurrentPosition. According to them, this function will try to get GPS data for the accuracy set. Under the hood enableHighAccuracy uses kCLLocationAccuracyBest 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 accuracy kCLLocationAccuracyBest 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,

  1. Lower your timeout and hope you get the desired accuracy. Better solution than using enableHighAccuracy:false (which will use like city level accuracy).
  2. Start watchPosition urself and stop, kind of complicated for simple use cases but still you have the option.

There are other accuracy options in iOS native API, but that is not supported in this library.

2reactions
Agontukcommented, Dec 1, 2020

kCLLocationAccuracyReduced is supported only in iOS 14. For iOS < 14, should we fall back to use threeKilometers ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Timeout about geolocation always reached when position ...
I use the below workaround to get GPS-only working. As low-accuracy is faster, the timeout is 4s. $cordovaGeolocation.getCurrentPosition({enableHighAccuracy: ...
Read more >
Geolocation.getCurrentPosition() - Web APIs | MDN
The default value is Infinity , meaning that getCurrentPosition() won't return until the position is available. enableHighAccuracy.
Read more >
cordova-plugin-geolocation
Returned when the device is unable to retrieve a position within the time specified by the timeout included in geolocationOptions . When used...
Read more >
react-native-geolocation-service Code Examples - Snyk
On Apple we can not detect when/if a * location permission has been granted or denied. For that reason after a * predefined...
Read more >
react-native-geolocation-service - npm
React native geolocation service for iOS and android. ... NOTE: Location request can still timeout since many android devices have GPS issue ...
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