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 on iOS is slow because it is always using high accuracy

See original GitHub issue

The geolocation plugin on iOS is taking a long time to get the users location because it is always using kCLLocationAccuracyBest or kCLLocationAccuracyBestForNavigation. Pull request #1773 added the option for enableHighAccuracy, but according to Apple’s developer documentation on kCLLocationAccuracyBestForNavigation: “Because of the extra power requirements, use this level of accuracy only while the device is plugged in.”. This level of accuracy seems like it is too high to be used for enableHighAccuracy.

The cordova plugin equivalent uses kCLLocationAccuracyThreeKilometers by default and kCLLocationAccuracyBest for high accuracy.

Ideally the user could choose the desired accuracy from all of the iOS options listed in the documentation, but these might not line up with android very well. Regardless the current implementation takes a long time to get the current location, especially when high accuracy is not required by the app.

Note that the long wait time to fetch the current location is not as noticeable on the simulator and a physical device should be used to see the true wait time.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:25 (7 by maintainers)

github_iconTop GitHub Comments

9reactions
WIStudentcommented, Sep 5, 2019

I just found a workaround that returns the location in less than 50ms on my iOS device, even with enableHighAccuracy set to true:

const internalGetCurrentPosition = async (options: GeolocationOptions = {}): Promise<GeolocationPosition> => {
  return new Promise<GeolocationPosition>((resolve, reject) => {
    const id = Geolocation.watchPosition(options, (position, err) => {
      Geolocation.clearWatch({id});
      if(err) {
        reject(err);
        return;
      }
      resolve(position);
    });
  });
};

What tipped me of was this article that says that using startUpdatingLocation() and stopUpdatingLocation() can be much faster than using requestLocation()

5reactions
WIStudentcommented, Sep 5, 2019

I am having the same issue. In my case it didn’t matter if enableHighAccuracy was set to true or false, getting the current position on iOS took each time around 10 seconds. On android on the other hand the position is returned almost immediately.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Poor GPS accuracy on iOS 11 / iPhone X - Apple Developer
My app is a workout and mapping app for Apple Watch and it used to be that the accuracy was better when using...
Read more >
Find & improve your location's accuracy - Google Maps Help
GPS : Maps uses satellites to know your location up to around 20 meters. When you're inside buildings or underground, the GPS is...
Read more >
How to Improve GPS Accuracy on an iPhone for Smooth ...
To improve GPS accuracy on an iPhone, you need to allow the device to automatically set your date and time based on your...
Read more >
Low GPS accuracy? Let's fix it! - speedohelp - Google Sites
It's also a good idea to try it with a different app, some that reports on location accuracy. If you still can't get...
Read more >
iOS: Location Services Not Working, fix - AppleToolBox
So to improve GPS accuracy, try the following: make sure the date, time, and time zone are set correctly by going to Settings...
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