ios - 如何从这种形式的xml中获取坐标 "lat,long"

标签 ios xml xcode annotations coordinates

我已经成功地从 xml 文件中获取了注释:

    double realLatitude = [[[anns objectAtIndex:i] objectForKey:@"Latitude"] doubleValue];

    double realLongitude = [[[anns objectAtIndex:i] objectForKey:@"Longitude"] doubleValue];


    MyAnnotation *myAnnotation = [[MyAnnotation alloc] init];
    CLLocationCoordinate2D theCoordinate;
    theCoordinate.latitude = realLatitude;
    theCoordinate.longitude = realLongitude;
    myAnnotation.coordinate=CLLocationCoordinate2DMake(realLatitude,realLongitude);

xml 文件如下所示:

<key>Latitude</key>
<string>60.490275</string>
<key>Longitude</key>
<string>22.255962</string>

但现在我有一个很大的点列表,其坐标如下所示:

<key>Coordinates</key>
<string>27.864849695000,70.080733147000</string>

我需要更改什么才能使我的代码正常工作?谢谢!

最佳答案

假设 anns 是包含解析的 xml 元素的数组:

NSString *coordinates = [[anns objectAtIndex:i] objectForKey:@"Coordinates"];
double realLatitude = [[[coordinates componentsSeparatedByString:@","] objectAtIndex:0] doubleValue];
double realLongitude = [[[coordinates componentsSeparatedByString:@","] objectAtIndex:1] doubleValue];

关于ios - 如何从这种形式的xml中获取坐标 "lat,long",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10688224/

相关文章:

sql - T SQL 导出到 XML

c# - 为每个循环创建 XName.Get In

xcode - 代码执行强度顺序(Swift)

ios - 具有动态大小内容的 UIScrollView

iphone - AFNetworking是否有连接失败后的重连方法

ios - 用于在线存储的 CloudKit

ios - 在 Parse 中安排后台作业

ios - Base64 PDF 内容转 PDF

xml - 带有 XPath 和多个命名空间的 SelectSingleNode

ios - 没有为应用商店上的应用程序找到有效的 'aps-environment' 权利字符串