iphone - String to CLLocation经纬度

标签 iphone objective-c string cllocation

我有两个表示纬度和经度的字符串,例如:“-56.6462520”,然后我想将其分配给 CLLocation 对象以与我当前的位置进行比较。我尝试了以下代码,但仅出现错误:

CLLocation * LocationAtual = [[CLLocation alloc]init];
LocationAtual.coordinate.latitude = @"-56.6462520";
LocationAtual.coordinate.longitude = @"-36.6462520";

然后将物体与我实际所在位置的经纬度进行比较。有什么建议吗?

最佳答案

您不能直接分配给坐标 - 它是 CLLocation 的只读属性。
使用以下实例方法:

- (instancetype)initWithLatitude:(CLLocationDegrees)latitude
                       longitude:(CLLocationDegrees)longitude

例子:

CLLocation *LocationAtual = [[CLLocation alloc] initWithLatitude:-56.6462520 longitude:-36.6462520];

关于iphone - String to CLLocation经纬度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7907734/

相关文章:

iphone - 向 UILabel 添加背景图像

ios - Xcode "Analyze"消息混淆

c++ - 我可以用 2 个字符替换字符串中的单个字符吗?

iphone - 在 iphone 中使用 ASIHTTPRequest

iphone - iOS 可点击词(UILabel 或 UIbutton 的)

ios - 带有 numberOfLines 和 lineBreakMode 的 UILabel

java - 如何从网页中获取特定文本

c - 用 scanf 读取 int 直到换行

iphone - 如何计算 NSString 中大写字符的数量?

objective-c - 解析 JSON objective c