坚持CoreLocation [英] Persisting CoreLocation

查看:94
本文介绍了坚持CoreLocation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我写的应用程序终止,我需要将当前位置存储到iphone上的'disk'。然后,当应用程序再次启动时,我想恢复此信息。但是,CLLocation坐标属性是只读的。

I have a need to store the current location to 'disk' on the iphone if the application I'm writing is terminated. Then, when the app starts again, I want to restore this information. However, the CLLocation coordinate property is read only.

如何在程序调用之间保存此信息(并将其重新应用于CLLocation对象)?

What can I do to save this information between program invocations (and reapply it to a CLLocation object)?

推荐答案

您可以使用NSDefaults来存储它。类似

You could use NSDefaults to store it. Something like

#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];

Sam

PS我不知道有一个mac手,所以上面的代码可能会有语法错误,但你明白了这一点:)

PS I don't have a mac to hand so there might be syntax errors in the above code but you get the idea :)

这篇关于坚持CoreLocation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆