Finding distances based on Latitude and Longitude

This JavaScript uses the Haversine Formula (shown below) expressed in terms of a two-argument inverse tangent function to calculate the great circle distance between two points on the Earth. This is the method recommended for calculating short distances by Bob Chamberlain (rgc@jpl.nasa.gov) of Caltech and NASA's Jet Propulsion Laboratory as described on the U.S. Census Bureau Web site.

dlon = lon2 - lon1
dlat = lat2 - lat1
a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2
c = 2 * atan2( sqrt(a), sqrt(1-a) )
d = R * c (where R is the radius of the Earth)

Note: this formula does not take into account the non-spheroidal (ellipsoidal) shape of the Earth. It will tend to overestimate trans-polar distances and underestimate trans-equatorial distances. The values used for the radius of the Earth (3961 miles & 6373 km) are optimized for locations around 39 degrees from the equator (roughly the Latitude of Washington, DC, USA).

GeoCode.com's TeleAtlas provides a form you can use to find the Latitude and Longitude for any U.S. address. I wrote a script to convert between decimal degrees and degrees/minutes/seconds formats.


First location (default: 1600 Pennsylvania Ave NW, Washington, DC)
Latitude: Longitude:
Expressed in decimal degrees

Second location (default: 1922 F St NW, Washington, DC)
Latitude: Longitude:
Expressed in decimal degrees


Results
miles
km

Was this page useful to you? Loading...