("Haversine formula")

for a full script go to http://www.movable-type.co.uk/scripts/LatLong.html

 

Calculate distance and bearing between two Latitude/Longitude points

 

Enter the co-ordinates into the text boxes to try it out. It accepts a variety of formats:

  • deg-min-sec suffixed with N/S/E/W (e.g. 40°44′55″N, 73 59 11W), or
  • signed decimal degrees without compass direction, where negative indicates west/south (e.g. 40.7486, -73.9864):

Lat 1: Long 1:

Lat 2: Long 2:

Calculation assumes a spherical earth, ignoring ellipsoidal effects, giving an ‘as-the-crow-flies’-distance between points.


This is the initial bearing which if followed in a straight line along a great-circle arc (orthodrome) will take you from the start point to the end point; in general, the bearing you are following will have varied by the time you get to the end point (if you were to go from say 35°N,45°E (Baghdad) to 35°N,135°E (Osaka), you would start on a bearing of 60° and end up on a bearing of 120°!).

For final bearing, take the initial bearing from the end point to the start point and reverse it (using θ = (θ + 180) % 360).


Just as the initial bearing may vary from the final bearing, the midpoint may not be located half-way between latitudes/longitudes; the midpoint between 35°N,45°E and 35°N,135°E is around 45°N,90°E.


Destination point given distance and bearing from start point

Given a start point, initial bearing, and distance, this will calculate the destination point and final bearing travelling along a (shortest distance) great circle arc.

Start Lat: Start Long:
Bearing (deg): Distance (km):

 

For final bearing, take the initial bearing from the end point to the start point and reverse it.


Rhumb lines

A ‘rhumb line’ (or loxodrome) is a path of constant bearing, which crosses all meridians at the same angle.

Lat 1: Long 1:

Lat 2: Long 2:


Given a start point and a distance d along constant bearing, this will calculate the destination point. If you maintain a constant bearing along a rhumb line, you will gradually spiral in towards one of the poles.

Start Lat: Start Long:
Bearing (deg): Distance (km):

 


Convert between degrees-minutes-seconds & decimal degrees

Latitude   Longitude   1° ≈ 111 km [110.57 eq'l - 111.70 polar]
    1' ≈ 1.85 km [= 1 nm] 0.001° ≈ 111 m
    1" ≈ 30.9 m 0.00001° ≈ 1 m

Note: Since the earth is not quite a sphere, there are small errors in using spherical geometry; the earth is actually roughly ellipsoidal (or more precisely, oblate spheroidal) with a radius varying between about 6,378km (equatorial) and 6,357km (polar), and local radius of curvature varying from 6,336km (equatorial meridian) to 6,399km (polar). This means that errors from assuming spherical geometry might be up to 0.55% crossing the equator, though generally below 0.3%, depending on latitude and direction of travel. An accuracy of better than 3m in 1km is good enough for me, but if you want greater accuracy, you could refine the result by using the local radius of curvature, as explained in the US Census Bureau.



© 2002-2006 Chris Veness