Search code examples
geolocationdatasetdistance

US states and cities distance from eachother


I'm building a web based application to determine a value, which consists the calculation of the distance between X city to Y city (US).

Is there a data resource to pull that information?


Solution

  • You can get the latitude and longitude of your cities from a map API. I use Yahoo's because their terms of service fit better with my needs, but the Google API is certainly a good choice as well.

    The Yahoo API is described here

    http://developer.yahoo.com/geo/placefinder/

    Once you have the latitude and longitude, you can find the distance either using a fairly straightforward formula

    Calculate distance between two latitude-longitude points? (Haversine formula)

    or with another API:

    http://developer.yahoo.com/flash/maps/classreference/com/yahoo/maps/api/utils/Distance.html