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