如何在我的iphone中获取格式化地址,例如谷歌网络服务的 Covington,AL,USA
来自以下网址 http://maps.google.com/maps/api/geocode/xml?latlng=31.319016,-86.399871&sensor=false
答案 0 :(得分:1)
- (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快得多。