Calculate distance, bearing and more between two latitude/longitude points

Distance

This page helps you to calculate great-circle distances between two points using the ‘Haversine’ formula.

The formula assumes that the earth is a sphere, (we know that it is "egg" shaped) but it is accurate enough* for our purposes.

Enter the coordinates 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:

And you can see it on a map (thanks to Google Maps)

Haversine formula:

R = earth’s radius (mean radius = 6,371km)
Δlat = lat2− lat1
Δlong = long2− long1
a = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
c = 2.atan2(√a, √(1−a))
d = R.c

(Note that angles need to be in radians to pass to trig functions).

The Haversine formula remains particularly well-conditioned for numerical computation even at small distances 

Spherical law
of cosines:
d = acos(sin(lat1).sin(lat2)+cos(lat1).cos(lat2).cos(long2−long1)).R
Excel:
=ACOS(SIN(Lat1)*SIN(Lat2)+COS(Lat1)*COS(Lat2)*COS(Lon2-Lon1))*6371

Bearing

Formula: θ = atan2( sin(Δlong).cos(lat2),
cos(lat1).sin(lat2) − sin(lat1).cos(lat2).cos(Δlong) )

Since atan2 returns values in the range -π ... +π, to normalise the result to a compass bearing, multiply θ by 180/π then use (θ+360) % 360, where % is modulo.

This is the initial bearing which if followed in a straight line along a great-circle arc 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 

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



Midpoint

Formula: Bx = cos(lat2).cos(Δlong)
By = cos(lat2).sin(Δlong)
latm = atan2(sin(lat1) + sin(lat2), √((cos(lat1)+Bx)² + By²))
lonm = lon1 + atan2(By, cos(lat1)+Bx)

Just as the initial bearing may vary from the final bearing, the midpoint may not be located half-way between latitudes/longitudes.


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

Standard Distance Conversions:

  • For miles, divide km by 1.609344
  • For nautical miles, divide km by 1.852

For every 15° that one travels eastward, the local time moves one hour ahead. Similarly, travelling West, the local time moves back one hour for every 15° of longitude.

Therefore, if we know the local times at two points on Earth, we can use the difference between them to calculate how far apart those places are in longitude, east or west.

This idea was very important to sailors and navigators in the 17th century. They could measure the local time, wherever they were by observing the Sun, but navigation required that they also know the time at some reference point, e.g. Greenwich, in order to calculate their longitude. Although accurate pendulum clocks existed in the 17th century, the motions of a ship and changes in humidity and temperature would prevent such a clock from keeping accurate time at sea.



Back To Anycalculator Home Page  John Harrison and the Longitude problem