【发布时间】:2015-06-25 08:31:05
【问题描述】:
我知道在大多数情况下,CLLocationManager 在初始化时会被调用两次,once with cached location data, and once with updated content。
这是有道理的,即使它在两种情况下都返回相同的结果(例如:因为模拟位置总是返回相同的坐标和精度)。
这是我启动过程的日志。 didUpdateToLocation 调用了两次,两次 oldLocation 都是 nil:
// Setup code:
let locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.distanceFilter = 100.0
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
// Log Output:
locationManager didUpdateToLocation
old: nil
new: <+22.28468100,+114.15817700> +/- 5.00m (speed -1.00 mps / course -1.00) @ 6/25/15, 3:21:57 PM Indochina Time
locationManager didUpdateToLocation
old: nil
new: <+22.28468100,+114.15817700> +/- 5.00m (speed -1.00 mps / course -1.00) @ 6/25/15, 3:22:01 PM Indochina Time
没有意义的是oldLocation 在这些情况下总是为零。我必须提供一个名为actualOldLocation 的外部变量来跟踪更新之间的距离变化。我做错了什么导致这个值为零吗?
【问题讨论】:
标签: ios mapkit cllocationmanager