I need a list of locations in the world, including countries, cities, counties, etc. in order to use these in my social network's location sharing feature.
Where can I find a database like that? (free/paid)
Open Data Stack Exchange is a question and answer site for developers and researchers interested in open data. It only takes a minute to sign up.
Sign up to join this communityThe US National Geospatial Intelligence Agency (NGA) has what you are looking for all countries in the world. The datasets (one per country) have country, administrative level divisions (e.g., states/counties), incorporated and unincorporated places, both in native language/script and in English.
https://www.nga.mil/ProductsServices/GeographicNames/Pages/default.aspx
I also have converted all the country datasets into Linked CSV format:
http://www.opengeocode.org/cude1.2/NGA/GNS/index.php
The United Nations Multilingual Terminology Database has administrative divisions/city names in the 6 UN languages. I don't think they have a direct dump, so you may need to scrap it:
http://unterm.un.org/dgaacs/unterm.nsf/
The US/NGA also took over maintaining the GEC (Geopolitical Codes):
http://earth-info.nga.mil/gns/html/gazetteers2.html
Here's my archive of the updates in the original FIPS/XLS format:
http://www.opengeocode.org/cude1.2/NGA/GEC/index.php http://www.opengeocode.com/
Per Deer Hunter's comments, here are links to the US Census Gazetteer files:
https://www.census.gov/geo/maps-data/data/gazetteer.html
Here's my version converted to linked CSV:
http://www.opengeocode.org/cude1.2/US%20Census/index.php
There is also the USGS Geographic Name Information System (GNIS) database for domestic and Antarctic names:
http://geonames.usgs.gov/domestic/download_data.htm
Here's my version converted to linked CSV:
http://www.opengeocode.org/cude1.2/USGS/GNIS/index.php
The Canadian (2011) census would also have geographic name information. Here's my version converted to linked CSV:
The OpenStreetMap project is an excellent source of worldwide data. They offer extracts on this page or via a map browser. Because it is a crowd-sourced dataset, it tends to be more complete in more developed countries, where internet and GPS availability is higher.
There are various tools for importing OSM data into Postgres, such as osm2pgsql. Nominatum is an address lookup service, based on OSM.
You might also find the Global Urban Extents from Global Rural-Urban Mapping Project dataset to be helpful.
I'd use http://geonames.org - it provides alternate names for many different languages for many of the cities in the database, which may be useful if your app is used worldwide.
You may be interested in Poplus APIs MapIt and Represent http://mapit.poplus.org/ http://represent.poplus.org/