【发布时间】:2013-02-14 16:54:03
【问题描述】:
如何在我的 iphone 中获取像 Covington, AL, USA 这样的格式化地址
来自以下网址 http://maps.google.com/maps/api/geocode/xml?latlng=31.319016,-86.399871&sensor=false
【问题讨论】:
-
错误,解析XML并提取
<formatted_address>标签?
如何在我的 iphone 中获取像 Covington, AL, USA 这样的格式化地址
来自以下网址 http://maps.google.com/maps/api/geocode/xml?latlng=31.319016,-86.399871&sensor=false
【问题讨论】:
<formatted_address>标签?
- (void) getAddress
{
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://maps.google.com/maps/api/geocode/json?latlng=31.319016,-86.399871&sensor=false"]];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
NSString *str = [[[dict objectForKey:@"results"] objectAtIndex:0] valueForKey:@"formatted_address"];
NSLog(@"Address = %@", str);
}
使用这个 json 这比 xml 快得多。
【讨论】: