Search code examples
iphoneiosios5ios4ios6

Get states of a country when a country is selected


I have a code where it shows all countries and we can select a specific country from it. What i want now is when i select a country i want to see the list of states in that country. Can any one please help me in that ? Is there a method or API for it? Any help is appreciated. thanks


Solution

  • Use db for getting countries and its states. Just download it.

    Now use this db to query like this:

    NSString *queryString = [NSString stringWithFormat:@"select zone_id , name from
                       zone where country_id = %d", countryID]; //here countryID is country code
    

    EDIT : Get all countries with query like this:

    NSString *queryStrAllCountries = [NSString stringWithFormat:@"select name from
                       countries"]; 
    

    Get countryID from country selected with query like this:

     NSString *queryStrCountry = [NSString stringWithFormat:@"select country_id from
                       countries where name='%@'", countryName]; //provide country name selected
    

    Refer this answer which provide information as the same.