For me to include in my project, I am looking for some API which can recognize the places and give the output as the distance between two places.

Is there any database that consists of distance matrix between all places in the USA ?

API something similar to Distance Calculator, which is able to recognize all the places and give the distance output for free. Google API is being charged. As per this link, I cannot enter geo coordinates, I can enter only the place name, it should be able to recognize and find the distance.

  • 1
    A distance matrix of all "places" in the USA would be enormous, no? Jul 13, 2018 at 20:18
  • I would start with geonames.org USA data and work from there. My github.com/barrycarter/bcapps/blob/master/bc-cityfind.pl does what you want, but for the entire world (it requires a working SQLite3 copy of the geonames db and a helper file found in the same directory).
    – user3856
    Jul 13, 2018 at 22:55
  • Google Maps only charges for a premium plan. What is the amount of calls you need (please edit into your question). Also: What distance: by car, on foot, as the dove flies...?
    – user4293
    Aug 7, 2018 at 7:38

2 Answers 2


National Bureau of Economic Research (NBER) has this data available in its County Distance Database.

Its incredibly detailed, and goes back to 1990.


If you use a list of places with the geocoordinates, you can easily script the distance calculation. This is much easier than calculating and storing all the distances ahead of time, include effort for re-calculation when the place dataset changes or updates.

Here's a sample python script (source):

import geopy.distance

coords_1 = (52.2296756, 21.0122287)
coords_2 = (52.406374, 16.9251681)

print geopy.distance.vincenty(coords_1, coords_2).km

To get the raw data, see these answers:

  • OSM more complete, can be all sorts of "places" and not just cities.

  • Geonames - cities of various sizes, easy CSV data model, easy to filter on US.

  • this is such a better answer than mine!
    – albert
    Jul 20, 2018 at 2:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.