アプリケーションでExpediaを使用してホテル予約アプリケーションを作成しています。州、国、つまり(タミルナードゥ州、インド)のリストを検索するための検索オプションがあります。iOSアプリケーションで都市と州の全データを取得する方法はありますか?[次の画像のような検索オプションがあります]
6967 次
2 に答える
1
これを実現するには、複数の API を呼び出さなければならない場合があります。以下の API を使用できます。
- http://api.drupal.org/api/drupal/includes%21locale.inc/function/country_get_list/7
- http://api.shopify.com/country.html
- http://www.geonames.org/export/web-services.html
この API を使用して、UITableView
. そしてUISearchBar
、ローカル検索を使用して検索できます。
注: これらの API を使用する場合は、アプリケーションの機能がこれらの API に依存していることに注意してください。それらが機能していない場合、アプリケーションは機能しません。それらのサービスがダウンしている場合、アプリケーションはダウンしています。
于 2013-02-15T10:51:23.233 に答える
0
最後に、これに対する解決策を見つけます。1)以下のURLを使用して、特定のテキストのjson形式ですべての都市名を取得しました。http://ws.geonames.org/searchJSON?name_startsWith=madurai
2)次に、json パーサーを使用してデータを解析します。以下にコードを含めます
NSURLRequest *req = [NSURLRequest requestWithURL:locatioURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSURLResponse *response;
NSError *errorReq = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&errorReq];
// NSString *udata = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
// NSString * newstr = [NSString stringWithFormat:@"%@",data];
NSString *udata = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSData *temp = [udata dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *dst = [[[NSString alloc] initWithData:temp encoding:NSASCIIStringEncoding] autorelease];
NSDictionary * locationDictionary = [[NSDictionary alloc]initWithDictionary:[dst JSONValue]];
NSMutableArray * locallocationArray= [[NSMutableArray alloc] initWithArray:[locationDictionary objectForKey:@"geonames"]];
NSLog(@"%@",locallocationArray);
for (int i = 0; i<[locallocationArray count]; i++)
{
NSString * locationStr = [NSString stringWithFormat:@"%@,%@,%@",[[locallocationArray objectAtIndex:i]objectForKey:@"name"],[[locallocationArray objectAtIndex:i]objectForKey:@"adminName1"],[[locallocationArray objectAtIndex:i]objectForKey:@"countryName"]];
[oneTimeLocationArray addObject:locationStr];
}
}
次に、配列を TableView にロードします。
3) Phonegap アプリケーションでこれを実装する必要がある場合は、以下のリンクを参照してくださいhttp://jqueryui.com/autocomplete/#remote-jsonp
ありがとう
于 2013-04-02T10:21:07.473 に答える