0

How can I get formatted address like Covington, AL, USA of google web service in my iphone

from the below url http://maps.google.com/maps/api/geocode/xml?latlng=31.319016,-86.399871&sensor=false

4

1 回答 1

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 快得多。

于 2013-02-28T13:32:39.117 回答