btmanikandan
btmanikandan

Reputation: 1931

How to get the state,country list in ios

I am creating hotel reservation application using Expedia in my application I am having search option to search list of state,country i.e(Tamilnadu,India). Is there is any way to get the whole data of city and state in my IOS application![I have the search option like the following Image]

enter image description here

Upvotes: 2

Views: 7555

Answers (2)

btmanikandan
btmanikandan

Reputation: 1931

Finally I find the solution for this. 1)I have used the below url and get all the city name in the form json for the particular text. http://ws.geonames.org/searchJSON?name_startsWith=madurai

2)And then parse the data with the help of json parser. I have Include my code below

       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];
}
}

Then load the array in the TableView.

3) If you need to implement this in Phonegap application means refer the below link http://jqueryui.com/autocomplete/#remote-jsonp

Thanks

Upvotes: 0

Rushi
Rushi

Reputation: 4500

You might have to call multiple API's to achieve this. You can use following API's.

  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

You can use this API's and fill your UITableView. And then you can search in UISearchBar using a local search.

Note: If you use these API's remember that your applications functionality is dependent on these API's. If they aren't working your application wont' work. If their services are down your application is down.

Upvotes: 1

Related Questions