2013-02-15 101 views
4

我正在使用Expedia在我的应用程序创建酒店预订应用程序我有搜索选项搜索州,国家(即泰米尔纳德邦,印度)名单。有没有什么办法让我的IOS应用城市和国家的全部数据![我有像下面的图片搜索选项]如何获得国家,在ios国家名单

enter image description here

+0

有没有什么办法可以解决这个问题 – btmanikandan 2013-02-22 13:24:14

回答

1

您可能需要调用多个API来实现这一目标。您可以使用以下API。

  1. http://api.drupal.org/api/drupal/includes%21locale.inc/function/country_get_list/7
  2. http://api.shopify.com/country.html
  3. http://www.geonames.org/export/web-services.html

您可以使用此API和填写您UITableView。然后您可以使用本地搜索在UISearchBar中进行搜索。

注意:如果您使用这些API,请记住您的应用程序功能依赖于这些API。如果他们不工作,你的应用程序将无法工作。如果他们的服务停止,您的应用程序就会停止运行

2

最后我找到了解决方案。 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

感谢

0

一件事,你可以使用JSON是。这个脚本给出了一个全面的json城市数据,其中不同国家的城市为关键。

为前:{[Uttar Pradesh: Lucknow, Kanpur, Agra ...],[Karnataka: Surathkal, Bangalore ]...}

这里是GitHub的链接:https://github.com/shauryashahi/Indian-State-City-db-json