【问题标题】:OSX (and also iOS): Is there a way to know the cached user GPS locations?OSX(还有 iOS):有没有办法知道缓存的用户 GPS 位置?
【发布时间】:2012-12-14 09:51:57
【问题描述】:

为了确定用户的位置,我使用了 CoreLocation 框架(我目前正在开发一个 OSX 应用程序(位置由 wifi 确定),但我的问题也可能适用于 iOS 应用程序)和以下委托方法:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

当由于某种原因无法找到用户位置时(例如,如果用户的计算机没有连接到互联网),则调用以下方法:

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error

在这种情况下,我想获取最后一个已知的用户位置。我想知道是否有办法获得这个最后一个已知位置。某处是否有一系列先前确定的位置?

【问题讨论】:

    标签: ios macos geolocation location


    【解决方案1】:

    请参考官方文档:

    http://developer.apple.com/library/ios/ipad/#documentation/CoreLocation/Reference/CLLocation_Class/CLLocation/CLLocation.html#//apple_ref/doc/c_ref/CLLocation

    据此,

    @property(readonly, nonatomic) CLLocation *location
    

    如果没有位置数据,则此属性的值为 nil 曾经被找回。 在 iOS 4.0 及更高版本中,此属性可能包含 启动时更新的位置对象。 具体来说,如果 重要的位置更新正在运行,您的应用程序正在运行 已终止,此属性将更新为最近的位置 重新启动应用程序时的数据(并且您创建了一个新的 位置管理器对象)。此位置数据可能比 您的应用程序处理的最后一个位置事件。

    所以这是获取最后一个已知位置的唯一方法。 如果不为nil,则可以使用!

    【讨论】:

    • 如果你要使用重大位置变更服务,不
    • 我不关心变化,我只需要知道5-10公里内的估计位置
    猜你喜欢
    • 2018-01-17
    • 2014-11-13
    • 1970-01-01
    • 2016-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-24
    • 1970-01-01
    相关资源
    最近更新 更多