harpreetkhalsagtbit / country-state-city

Basic library for Country, State and City
country-state-city.vercel.app
GNU General Public License v3.0
275 stars 177 forks source link

I am not able to add fetch counties by states (USA) #122

Open gorilla-James opened 1 year ago

gorilla-James commented 1 year ago

Hi! It would be nice to add the feature of fetching counties for a given state. Some countries may not have that structure but for countries like USA it would be really helpful

gorilla-James commented 1 year ago

And also be able get cities based on counties

harpreetkhalsagtbit commented 1 year ago

@gorilla-James I am afraid but you have to follow a long path for this. Bcoz even if you have state code - you may get multiple states from different countries, which you won't expect but many countries can have same state code. So you better have both state code and country code.

And, The long path is:

  1. Get all states
  2. Filter out state based on State name/code or country code if you have
  3. Once you get the state - using country code provided in the state json you can get the country.