Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 持续岩心定位_Iphone_Core Location - Fatal编程技术网

Iphone 持续岩心定位

Iphone 持续岩心定位,iphone,core-location,Iphone,Core Location,如果我正在编写的应用程序被终止,我需要将当前位置存储到iphone上的“磁盘”中。然后,当应用程序再次启动时,我想恢复此信息。但是,CLLocation坐标特性是只读的 如何在程序调用之间保存此信息并将其重新应用于CLLocation对象?您可以使用NSDefaults来存储它。差不多 #define kLocationLat @"LOCATION_LAT" #define kLocationLng @"LOCATION_LNG" // Store the location [[NSUserD

如果我正在编写的应用程序被终止,我需要将当前位置存储到iphone上的“磁盘”中。然后,当应用程序再次启动时,我想恢复此信息。但是,CLLocation坐标特性是只读的


如何在程序调用之间保存此信息并将其重新应用于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电脑,所以上面的代码中可能有语法错误,但您知道:

我假设removeObjectForKey可以工作,即使double不是严格意义上的对象!很好,我发现很抱歉没有使用NSUserDefaults和NSString常量为密钥设置CLLocation对象。它们肯定会使代码更干净-我没有检查CLLocation是否实现了NSCoding