Search code examples
iosswiftlocationcllocationmanager

In what scenarios would CLLocationManager return a current location array with more than one entry?


Background

According to the documentation for the delegate method locationManager(manager:locations:)

Parameter: locations [CLLocation]
An array of CLLocation objects containing the location data. This array always contains at least one object representing the current location. If updates were deferred or if multiple locations arrived before they could be delivered, the array may contain additional entries. The objects in the array are organized in the order in which they occurred. Therefore, the most recent location update is at the end of the array.

My question specifically is whether anyone knows exactly what they mean by the following sentence

If updates were deferred or if multiple locations arrived before they could be delivered, the array may contain additional entries.

Question

Could someone shed some light on what scenarios would lead to "deferred location updates" or "multiple location updates"?

  • Does this occur when someone has approximate location but not precise location enabled?

  • Does this occur when the user is switching between our app and another app very quickly?

  • Does this occur when GPS signal is not strong enough (e.g. inside an elevator)?


Solution

    1. Does this occur when someone has approximate location but not precise location enabled?

      No

    2. Does this occur when the user is switching between our app and another app very quickly?

      No

    3. Does this occur when GPS signal is not strong enough (e.g. inside an elevator)?

      Can be, Location Service (or CLLocationManager) will try to get the best location that matches your configuration for CLLocationManager. So it can return a list of coordinates after a delay to wait for the best location.

    For the deferred update, you can check this: https://developer.apple.com/documentation/corelocation/cllocationmanager/1620547-allowdeferredlocationupdates