didUpdateToLocation 调用了两次,ok。为什么 oldLocation 两次都是零?

didUpdateToLocation called twice, ok. Why is oldLocation nil both times?

我了解到在大多数情况下 CLLocationManager 在 init 上被调用了两次,once with cached location data, and once with updated content

这是有道理的,即使它 returns 两种情况下的结果相同(例如:因为模拟位置总是 returns 相同的坐标和精度)。

这是我的启动过程的日志。 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 在这些情况下总是 nil。我必须提供一个我称之为 actualOldLocation 的外部变量来跟踪更新之间的距离变化。我是不是做错了什么导致这个值为零?

您的目标 iOS 是什么? didUpdateToLocation 已从 iOS 6.0 中弃用,不确定它现在是否完全可用。