Where can I get a list of Countries, States and Cities?

183,465

Solution 1

The UN maintains a list of countries and "states" / regions for economic trade. That DB is available here: http://www.unece.org/cefact/locode/welcome.html

Solution 2

geonames.org has an api and a data dump of worldwide geographical places.

Solution 3

geonames is nice. an export tool based on geonames:

https://github.com/yosoyadri/GeoNames-XML-Builder

https://github.com/yosoyadri/GeoNames-XML-Builder/blob/master/continents-countries-statesprovinces.xml

there's also the excellent pycountry module:

http://pypi.python.org/pypi/pycountry

Solution 4

Check this out! It was built no longer ago in 2014.

Get a list of country/state/city in a hierarchy using geonames webservice

Solution 5

Geonames has a lot of data on places (including towns and cities) but it seems to be contributed and perhaps not complete.

Perhaps also try SQL Dumpster, I've used this website a lot for these kinds of databases, cities, provinces, etc. Unfortunately it's not free but only appears to be a one-time fee.

Share:
183,465
Jonathan
Author by

Jonathan

Hello, I'm Jonathan! 👋 Experienced in Front End Development (HTML, CSS, ES6, Angular, React), Back End Development (C#, Java, NodeJS) and Software Engineering (OOP, RDBMS, TDD and beginning to branch into FP). Additionally trained and experienced in Interaction Design (User Research, Sketching, Wireframing, Prototyping, Accessibility). Focused on user needs, with an emphasis on relationships, empathy, evidence and results. I enjoy working in diverse, multi-disciplinary teams, learning and sharing knowledge. Made significant and lasting contributions to several high-impact projects in Australia, for: Bupa (2010), Westpac (2013), Service NSW (2015) and the Digital Transformation Agency (2017). Worked remotely for 5+ clients (including production support and across time-zones), with high self-motivation, productivity and communication (over email, IM and pull-requests). • Continuously programming since 2000 •

Updated on July 05, 2022

Comments

  • Jonathan
    Jonathan almost 2 years

    This probably seems like a duplicate, since there are identical questions out there.

    Unfortunately all of the answers to all of these questions are missing one detail: the states.

    Where can I get a list of countries, states and cities?

    For example, I want this:

    | Sydney  |  New South Wales  |  Australia  |
    

    or

    |  Miami  |  Florida          |  United States  |
    

    I don't want something like this, which excludes the state:

    |  Miami  |  United States  |
    

    Is there any place where I can get this kind of data?

    I've already tried the following data sources:

    But all of them exclude the states.

  • Jonathan
    Jonathan about 12 years
    I can't find any list of Countries, States and Cities on this website. All I can find is a list of countries, a list of capital cities and capitals.
  • Shane Andrade
    Shane Andrade about 12 years
    I think you're looking at the browse features of the site. Look at the data that you can export from them here download.geonames.org/export/dump
  • Jonathan
    Jonathan about 12 years
    I looked through the list of files. There seems to be nothing there that simply lists countries and states. There are lists of cities, highly detailed lists of locations, lists of countries and country-specific lists which contain a grab-bag of location types including states and small localities (with nothing to indicate which items are states and which aren't; since some countries would call them 'State of' but other countries would call them something else, e.g. 'Province of'). This isn't very useful I'm afraid.
  • Shane Andrade
    Shane Andrade about 12 years
    I believe what you are looking for is what they call the admin 1 zones and can be found in the admin1CodesASCII.txt file from that previous link.
  • Jonathan
    Jonathan over 11 years
    So this is slightly better. At least I can see states per country. So I can get this: 'New South Wales | Australia'. Unfortunately this still doesn't give me what I wanted originally. I want this: 'Sydney | New South Wales | Australia'. I want the city AND state AND country, not just the state and country. Perhaps I should just be happy with this and match the cities up by state name, but then I'd need a list of cities and states, which I still don't have.
  • Jonathan
    Jonathan over 10 years
    Thanks Eric!! This is much closer to what I need. Their CSV files have a format like this: Country Code | ... | Locality | Locality/City | State. This isn't ideal, but it gives me the info I need. All I need to do is use a string splitting function to parse out the City name, then I've got what I want: Locality | City | State. Thanks a tonne!
  • Roy Lee
    Roy Lee over 10 years
  • bcsteeve
    bcsteeve over 8 years
    @Roylee when it can't even get my first world country's city of 200,000 people included in the list, it obviously isn't complete. I wouldn't recommend that data.
  • Apollo Grace
    Apollo Grace over 6 years
    I've been using an import of the Geonames "cities1000" database pretty heavily over the last year - this theoretically includes all cities in the world over 1000 in population, and also happens to include many with fewer people. I haven't hit upon any notable omissions yet; makes me wonder where bcsteeve lives.
  • Junaid Atari
    Junaid Atari almost 6 years
    Link is dead by now!
  • Roy Lee
    Roy Lee almost 6 years
    I've just tried the link, its still working. @JunaidAtari :)
  • Daryl Wong
    Daryl Wong over 5 years
    Hi Jonathan, may I know what the url for this list? Somehow I could not find country, state, city data in the UN website.
  • Savage
    Savage over 5 years
    Countries: geonames.org/countries - is this list not accurate? It seems to be quite exhaustive with 252 entries, although you might argue that not everything in that list is a country.
  • kiatng
    kiatng almost 5 years
    Unfortunately, it doesn't contain state/region/admin_level when I downloaded the csv data and checked it today. See manual.
  • Arefe
    Arefe over 4 years
    @kiatngI just downloaded this data and find the state-level data is included. "MY","01","Johor","State" "MY","02","Kedah","State"
  • Philip Enc
    Philip Enc almost 4 years
    Please upload a file to dropbox, to enable the download. It would be very helpful.
  • GDP
    GDP almost 4 years
    @philip-enc I don't have the database I was referring to anymore, but you can get what you need at geodatasource.com/world-cities-database/free or just google "free world city state country database"
  • Philip Enc
    Philip Enc almost 4 years
    Thank for the response but I already spent a lot of time with free databases and I found bugs, duplicated entries.... Now I am searching for something to pay and solve the problem. I you have some advice, you are welcome. Thanks