我已经成功地从 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/