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

时间:2021-11-17 21:19:54

I have successfully got annotations from xml file with this:

我已成功从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 file looks like this:

xml文件如下所示:

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

but now I have a large list of points with coordinates that's look like this:

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

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

what I need to change that my code works? Thanks!

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

1 个解决方案

#1


1  

Assuming that anns is the array with the parsed xml elements:

假设anns是带有解析的xml元素的数组:

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

#1


1  

Assuming that anns is the array with the parsed xml elements:

假设anns是带有解析的xml元素的数组:

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