CLLocationManager.requestLocation () takes about 10 seconds

CLLocationManager.requestLocation() for didUpdateLocations CLLocationManager.requestLocation() event takes about 10 seconds.

Here are the attributes set for CLLocationManager

 let locationManager = CLLocationManager() locationManager.delegate = self locationManager.desiredAccuracy = kCLLocationAccuracyBest locationManager.distanceFilter = 10 locationManager.requestWhenInUseAuthorization() locationManager.requestLocation() 

According to the documentation, this may take several seconds.

This method returns immediately. When it is called, the location manager receives a location fix (which may take several seconds) and calls the delegate locationManager method (_: didUpdateLocations :) with the result.

But can it take 10 long seconds? Or am I missing something?

+8
source share
2 answers

If you disconnect

 locationManager.requestLocation() 

for

 locationManager.startUpdatingLocation() 

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

+6
source

I think you have a false premise. This Google is always faster. I assume that your building application is from scratch and the application does not have access to the cache. Otherwise, GoogleMaps may also take more than 3 seconds. Obviously, I don’t know the exact features, but I just think that when you use GoogleMaps, you use it as a user, and now, when you are developing your own application, you think of it as a developer, i.e. Be more meticulous about it.

Also, to have the best of comparisons, make sure you set desiredAccuracy to BestForNavigation , distanceFilter to 0 and activityType to .automotive . This is usually what navigation apps do.

Leo's comment is also important: make sure you update the interface from the main queue

And as experienced Core-Location users: a programmer and Paulw11 already mentioned:

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

0
source

All Articles