【问题标题】:How to get old Location value from the didUpdateToLocation method in swift如何从 swift 中的 didUpdateToLocation 方法中获取旧的位置值
【发布时间】:2015-06-03 13:20:29
【问题描述】:

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

有什么办法可以得到旧位置还是我错过了什么?

【问题讨论】:

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


    【解决方案1】:

    不再有oldLocation,因此您将不得不依赖返回的CLLocation 中的timestamp。您可以使用timeIntervalSinceNow 对照当前时间检查它是否是新的。

    【讨论】:

    • 有什么办法可以得到准确的旧位置吗?
    • 最好的办法是在收到时将其存储在 var 中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-14
    • 1970-01-01
    • 2012-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多