1

私のiPhoneアプリでは、GoogleAPIを使用しています。私がしなければならないことの1つは、国のドロップダウンがあり、国を選択するときに、その国のすべての都市を取得する必要があることです。Google APIで可能ですか、それとも他のものを使用する必要がありますか。提案してください!ありがとう-

4

1 に答える 1

2

Google Geocoder API は JSON を返します。これは単なる GET メソッドを使用する Web サービスの一種です。

そして、これは Google Gecoder API です。これはその Web サービスへのリンクです。このリンクでは、地域名をロンドンとしています。あなたはあなたの国名を与えることができます

注: SBJson ライブラリをコードに含める必要があります。

そのリンクの最後に住所を追加しました。住所を追加する場合は、地域名を指定する必要があります(または)緯度と経度を追加する場合は、座標を指定する必要があり、それに応じて結果が返されます。

そして、Google APIを呼び出すためのコードは次のようになります

 //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応答ですべての名前を短い名前、長い名前などの形式で取得できます.

于 2012-05-22T14:26:15.293 に答える