CLLocationManager.requestLocation() takes about 10 seconds CLLocationManager.requestLocation() takes about 10 seconds ios ios

CLLocationManager.requestLocation() takes about 10 seconds


If you switch out the

locationManager.requestLocation()

for

locationManager.startUpdatingLocation() 

then didUpdateLocations will start firing immediately. This should solve your problem.


TL;DR

requestLocation() is a convenient method provided by Apple which under the hood will run startUpdatingLocation() , retrieve multiple location data, and select the most accurate one to pass to delegate, and call stopUpdatingLocation()

This process can take up to 10 seconds (which is around the timeout limit) if it can't decide which location data is the best.


I think you have a false premise. That Google is always faster. I'm guessing that your building app from scratch and the app has no access to cache. Otherwise GoogleMaps can also sometimes take more than 3 seconds. Obviously I don't know the exact specifics but I just think when you're using GoogleMaps you're using it as a user and now when you're developing your own app you're thinking about it as a developer ie you're being more meticulous about it.

Also to have the best of comparisons make sure you set your desiredAccuracy to BestForNavigation, distanceFilter to 0 and activityType to .automotive. That's normally what navigation apps are doing.

Leo's comment is also important: Make sure you update the UI from the main queue

And as mentioned by both highly experienced in Core-Location users: programmer and Paulw11:

When you call startUpdatingLocation on the location manager you must give it time to get a position. You should not immediately call stopUpdatingLocation. We let it run for a maximum of 10 seconds or until we get a non-cached high accuracy location.