2013-02-15 6 views
4

신청서에 Expedia를 사용하여 호텔 예약 신청서를 작성하고 있습니다. 국가, 국가 (Tamilnadu, India)의 목록을 검색 할 수있는 검색 옵션이 있습니다. 내 IOS 응용 프로그램에서 도시와 국가의 전체 데이터를 얻을 수있는 방법이있다!국가, 국가 목록을 ios로 가져 오는 방법

enter image description here

+0

인가 : 여기 {[Uttar Pradesh: Lucknow, Kanpur, Agra ...],[Karnataka: Surathkal, Bangalore ]...}

은 GitHub의 링크입니다 – btmanikandan

답변

1

은 여러 API의이를 달성하기 위해 전화를해야 할 수도 있습니다 [I는 다음 이미지와 같은 검색 옵션이 있습니다]. 다음 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를 채울 수

    1. . 그런 다음 로컬 검색을 사용하여 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) 아래의 링크를 http://jqueryui.com/autocomplete/#remote-jsonp

    감사합니다 당신이 JSON이다 사용할 수 있습니다

    관련 문제