Where can I get a list of Countries, States and Cities?
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
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.
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, 2022Comments
-
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:
- http://www.maxmind.com/app/csv
- http://www.geodatasource.com/world-cities-database/free
- http://developer.yahoo.com/geo/geoplanet/data/
But all of them exclude the states.
-
Jonathan about 12 yearsI 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 about 12 yearsI 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 about 12 yearsI 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 about 12 yearsI 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 over 11 yearsSo 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 over 10 yearsThanks 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 over 10 yearscheck this out vikku.info/programming/geodata/…
-
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 over 6 yearsI'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 almost 6 yearsLink is dead by now!
-
Roy Lee almost 6 yearsI've just tried the link, its still working. @JunaidAtari :)
-
Daryl Wong over 5 yearsHi Jonathan, may I know what the url for this list? Somehow I could not find country, state, city data in the UN website.
-
Savage over 5 yearsCountries: 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 almost 5 years
-
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 almost 4 yearsPlease upload a file to dropbox, to enable the download. It would be very helpful.
-
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 almost 4 yearsThank 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