Google Geocoder API 返回 JSON, 它只是一个网络服务,
https:// developmenters.google.com/maps/documentation/geocoding/"rel="nofollow" >这个 是Google Gecoder API和这个链接是这个网络服务的链接,在这个链接中,我把区域命名为london。您可以给您国家名称 。
注意: 您需要将 SBJson 库包含在代码中 。
该链接的末尾,我附加了地址,如果您附加了地址,如果您要附加纬度和经度,您需要给出区域名称(或),您需要给出坐标,结果将相应返回。
呼叫谷歌阿皮的代码会像这样
//Call the Google API
NSString *req = [NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?sensor=false&address=%@", esc_addr];
NSLog(@"The get address is %@", req);
//Pass the string to the NSURL
NSString *result = [NSString stringWithContentsOfURL:[NSURL URLWithString:req] encoding:NSUTF8StringEncoding error:NULL];
NSLog(@"The result is %@", result);
//Initialize the SBJSON Class
SBJSON *parser = [[SBJSON alloc] init];
NSError *error = nil;
//Get the resullts and stored in the address array
addressArray = [parser objectWithString:result error:&error];
//Get the latitude values for the given address
NSDictionary *dict = [[[addressArray valueForKey:@"results"] valueForKey:@"geometry"] valueForKey:@"location"];
self.latitudeValue = [[dict valueForKey:@"lat"] objectAtIndex:0];
self.longitudeValue = [[dict valueForKey:@"lng"] objectAtIndex:0];
NSLog(@"LAT : %@",self.latitudeValue);
NSLog(@"LONG : %@",self.longitudeValue);
我刚刚给了一个想法, 你可以在JSON的回答中 以短名、长名等形式 把所有名字都写成短名、长名等