Take the 2-minute tour ×

Where can one obtain an open source or licensable database of latitudes and longitudes for various cities?

share|improve this question
add comment

9 Answers

up vote 29 down vote accepted

Looks like MaxMind opened theirs up for free. See this post for more information and download it here.

share|improve this answer
Its not correct, the database does not specify state, which is kind of confusing in many case as you have multiple cities in same countries but different states. –  Akash Kava Jun 7 '13 at 2:32
add comment

This is a great question that naturally leads to other questions. Cities are not located at a single latitude and longitude, so first you need to decide whether you want a list of the locations of city "centers" or if you want to do geographic queries on the areas covered by cities.

Mapping From City Name to Latitude and Longitude

If you are trying to map from city name to lat/lon, then you will want a list of cities with the lat/lon of an interior point, probably the city's logical center (not its geographic center, which is often far away from downtown). In such a case, I would start with:



Both have downloadable files with easy to parse formats and are regularly updated. They include much more than cities (e.g., they include public buildings, places of interest, parks, etc.), but each record includes a type field that indicates what type of record it is. You can easily filter such records to only include cities and towns, for example.

You can find similar datasets from non-governmental sources such as:



But I would start with the governmental sources, as they are updated regularly by well funded government departments. MaxMind is a private company and GeoNames is an open source project.

Mapping From Latitude and Longitude to City

If you are starting from lat/lon and are interested in finding what city contains that point, then you should take a different approach.

First, point locations of city centers are not the best way to do it, since cities are defined by areas, not points. And that is not just a technicality. Using point locations may work for small towns surrounded only by unincorporated land, but in a metropolitan area where the various suburbs share borders, this method will lead to mistakes very often. If you want to do it this way anyway, you'll need two main components:

  • First, you'll need to use the Haversine formula, which computes the distance between two locations, specified by lat/lon. With this you will be able to compute the distance between a given query point and any of the cities in your list. See How do I calculate distance between two latitude longitude points? for details.
  • Unfortunately, that formula is computationally expensive and there are a lot of cities in the US and even more in the world. So if you want your look-up to be fast, you'll want to implement a spatial index. The simplest (and fastest, in my experience) such index, is a grid index. This is just a two dimensional array of lists of references to cities. The two dimensions correspond to latitude and longitude and you can find the cell of that array corresponding to a given lat/lon by just re-scaling the lat/lon from (-180, 180), (-90, 90) to (0, N), (0, M), where there are NxM cells in the array. To populate this index, you just loop over all the entries in your city list and add each city to all of the cells that are within a given radius of that cell.

The better way to do it is to use a map of the cities, where each city is represented by a polygon representing the area of the city. For the US, such maps are readily available from the US Census. To query a map like that you'll need a different set of tools. I've explained how to do this in another answer: http://stackoverflow.com/a/10490201/688365. For some reason, that post was voted down, presumably because I mentioned my web site that sells related services. But the information is good. My web site provides an API to do things like this, and sells a Java library if you want to do it on your own server:


The API is free for non-profits, non-commercial open source projects, and academic researchers. We charge a modest fee for API access to cover our serving costs, and the Java libraries are a bit more expensive, but offer the best solution for businesses that care about latency and reliability.

share|improve this answer
add comment

Geonames has long/lat as well as city, postal and other location type data. It is free as well.

share|improve this answer
add comment


EDIT: unclear why I was modded down, this will indeed give you lat/lon for a zip or city!

share|improve this answer
because he wanted a database not an api –  Carter Cole May 2 '13 at 0:03
add comment

If you need to host it locally or import it into your own database or gaz service, the USGS and NGA provide a comprehensive list of cities with lat/lon. It's updated reguarly, free, and reliable.



share|improve this answer
add comment

Not freely available, but pretty easy to get: IATA SSIM tapes are published weekly and contain all scheduled flights, worlwide. There is a port (airport) table inside which contains all airports (cities) and their lats/lons. These are useful for calculating official airline distances between cities for eg. ticketed point mileages etc. Most people who work for an airline can get you a copy of a recent SSIM 'tape' which is basically a big file - they are useful for all sorts of things as well. eg. timezone info, aircraft info too.

share|improve this answer
add comment

Here's one.

share|improve this answer
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. –  antony.trupe Aug 31 '12 at 2:14
@antony.trupe I agree this is good advice for many scenarios, but this question simply asks for the location of a downloadable file, which that link provides. In this case, what are "the essential parts of the answer"? –  Ian Nelson Aug 31 '12 at 7:00
@antony.trupe And really, you're commenting on an answer I gave four years ago! Give me a break :-) –  Ian Nelson Aug 31 '12 at 7:01
my comment is canned text used by the review system. –  antony.trupe Sep 3 '12 at 0:45
add comment

Yahoo! Place finder provides an easy to use rest API




Example usage taken directly from the main page:


share|improve this answer
add comment

maxmind has a free database. you can get that one...

There was also one open source database shared on Google but it is no longer updated but you can check that one too

If you are looking for professional vendors then www.worldcitiesdatabase.com and www.geonames.org are likely candidates

share|improve this answer
add comment

Your Answer


