如何从这个形式的“lat,long”获取xml的坐标

时间:2012-05-21 15:34:13

标签: 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>

我需要改变我的代码是什么?谢谢!

1 个答案:

答案 0 :(得分:1)

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

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