如何从swift中的didUpdateToLocation方法获取旧的Location值

时间:2015-06-03 13:20:29

标签: ios swift cocoa-touch core-location cllocationmanager

在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
}

有没有办法获得旧位置或我错过了什么?

1 个答案:

答案 0 :(得分:0)

不再有oldLocation,因此您必须依赖timestamp返回的CLLocation。您可以使用timeIntervalSinceNow检查当前时间是否为新内容。