ios - OSX(还有 iOS): Is there a way to know the cached user GPS locations?

标签 ios macos geolocation location

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

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

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

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

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

最佳答案

请引用官方文档:

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

The value of this property is nil if no location data has ever been retrieved. In iOS 4.0 and later, this property may contain a more recent location object at launch time. Specifically, if significant location updates are running and your application is terminated, this property is updated with the most recent location data when your application is relaunched (and you create a new location manager object). This location data may be more recent than the last location event processed by your application.

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

关于ios - OSX(还有 iOS): Is there a way to know the cached user GPS locations?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14081237/

相关文章:

javascript - 各种浏览器中的 HTML5 地理定位 API

ios - CFDictionary 更新到 PHPhotoLibrary kCGImagePropertyExifDictionary 不采取

macos - 启动使用 Clang 构建的 MacOS 应用程序时出错

macos - 修改我的 OSx 系统上的 Idea vm 内存选项没有改变任何东西

xcode - Swift 对象的 UID

html - 哪些网络浏览器支持通过 HTML5 进行地理定位?

php - Haversine计算: Show users within set

ios - 如何将 Storyboard View 分解为 XIB

ios - UITextView 字体为零

ios - 如何显示从数据库中获取的值?