Iphone 持续岩心定位
如果我正在编写的应用程序被终止,我需要将当前位置存储到iphone上的“磁盘”中。然后,当应用程序再次启动时,我想恢复此信息。但是,CLLocation坐标特性是只读的Iphone 持续岩心定位,iphone,core-location,Iphone,Core Location,如果我正在编写的应用程序被终止,我需要将当前位置存储到iphone上的“磁盘”中。然后,当应用程序再次启动时,我想恢复此信息。但是,CLLocation坐标特性是只读的 如何在程序调用之间保存此信息(并将其重新应用于CLLocation对象)?您可以使用NSDefaults来存储它。差不多 #define kLocationLat @"LOCATION_LAT" #define kLocationLng @"LOCATION_LNG" // Store the location [[NSUse
如何在程序调用之间保存此信息(并将其重新应用于CLLocation对象)?您可以使用NSDefaults来存储它。差不多
#define kLocationLat @"LOCATION_LAT"
#define kLocationLng @"LOCATION_LNG"
// Store the location
[[NSUserDefaults standardUserDefaults] setDouble:location.coordinate.lat forKey:kLocationLat];
[[NSUserDefaults standardUserDefaults] setDouble:location.coordinate.lng forKey:kLocationLng];
// Retrieve the location
CLLocationDegrees lat = [[NSUserDefaults standardUserDefaults] doubleForKey:kLocationLat];
CLLocationDegrees lng = [[NSUserDefaults standardUserDefaults] doubleForKey:kLocationLng];
CLLocation *location = [[CLLocation alloc] initWithLatitude:lat longitude:lng];
萨姆
PS我手头没有mac电脑,所以上面的代码中可能有语法错误,但你知道:)你可以使用NSDefaults来存储它。差不多
#define kLocationLat @"LOCATION_LAT"
#define kLocationLng @"LOCATION_LNG"
// Store the location
[[NSUserDefaults standardUserDefaults] setDouble:location.coordinate.lat forKey:kLocationLat];
[[NSUserDefaults standardUserDefaults] setDouble:location.coordinate.lng forKey:kLocationLng];
// Retrieve the location
CLLocationDegrees lat = [[NSUserDefaults standardUserDefaults] doubleForKey:kLocationLat];
CLLocationDegrees lng = [[NSUserDefaults standardUserDefaults] doubleForKey:kLocationLng];
CLLocation *location = [[CLLocation alloc] initWithLatitude:lat longitude:lng];
萨姆
PS我手头没有mac电脑,所以上面的代码中可能有语法错误,但你知道:)我假设removeObjectForKey可以工作(即使double不是严格意义上的对象!)完美,我也发现了这一点(很抱歉没有RTFM'ing)使用NSUserDefaults和NSString常量为键设置CLLocation对象。它们肯定会使代码更干净-我没有检查
CLLocation
是否实现了NSCoding
我假设removeObjectForKey可以工作(即使严格来说double不是对象!)完美,我也发现了这一点(很抱歉没有RTFM'ing)使用NSUserDefaults和NSString常量为键设置CLLocation对象。它们肯定会使代码更干净-我没有检查CLLocation
是否已实现NSCoding