【发布时间】:2011-11-04 03:41:29
【问题描述】:
使用 http://maps.google.com/maps/geo?q=.... 返回纬度和经度,如下所示: 48.8616441,2.3448885
在这样的返回字符串中: 200,8,48.8616441,2.3448885
当将 a 解析为返回 CLLocationCoordinate2D 的函数时:
NSArray* listItems = [locationString componentsSeparatedByString:@","];
CLLocationDegrees latitude = kInexistantLatitude;
CLLocationDegrees longitude = kInexistantLongitude;
if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) {
latitude = [[listItems objectAtIndex:2] doubleValue];
longitude = [[listItems objectAtIndex:3] doubleValue];
}
CLLocationCoordinate2D location;
location.latitude = latitude;
location.longitude = longitude;
return location;
它提供给调试器:
纬度 = 48.861644099999999 经度 = 2.3448885000000002
我将许多像这样的项目存储到一个数组中,最后,我解析数组以将它们作为字典项目(标记)写入 plist 文件(我使用一个 NSString appendFormat 给出,如 NSLog):
NSLog(@"%f %f", location.latitude, location.longitude);
48.861644 2.344889
在某个时刻,我将加载该字典,并将读取的内容存储到 CLLocationCoordinate2D 中以将其显示在 MKMapView 上。
所以我有两个问题:
1) 如何在不丢失数字的情况下存储 http 请求给出的返回值并保留我的功能?
2) 如果我能做到这一点,我怎样才能读取这些内容并将其存储到 CLLocationCoordinate2D 中而不会再丢失一个数字?
【问题讨论】:
标签: iphone string cocoa-touch double coordinates