2012-05-21 56 views
0

我已經成功地得到了與此從XML文件註釋:如何從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

假設anns與解析xml元素的數組:

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

謝謝!很棒 –