在Objective C中,我获得了用户的旧位置和新位置 使用以下方法
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
if (oldLocation == nil) return;
BOOL isStaleLocation = ([oldLocation.timestamp compare:self.startTimestamp] == NSOrderedAscending);
...
}
现在我将代码移植到Swift,我无法通过以下方法获取旧位置
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
self.currentLocation = manager.location
}
有没有办法获得旧位置或我错过了什么?
答案 0 :(得分:0)
不再有oldLocation
,因此您必须依赖timestamp
返回的CLLocation
。您可以使用timeIntervalSinceNow
检查当前时间是否为新内容。