English 中文(简体)
如何在 iPhone App 上为一个国家建立所有城市
原标题:How to get all the cities for a country in iPhone App

我在使用 Google API 的 iPhone 应用程序中 。 我要做的一件事是, 我有一个国家下降, 当我选择任何国家时, 我需要从这个国家的所有城市中取回。 是否与 Google API 或我使用其他任何城市。 请建议! Thanks

问题回答

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的回答中 以短名、长名等形式 把所有名字都写成短名、长名等





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签