HomeTime & Geography › Haversine Distance Calculator

Haversine Distance Calculator

Computes the great-circle (as-the-crow-flies) distance between two points on a spherical Earth with the haversine formula, in kilometres, miles and nautical miles, together with the initial bearing, compass direction and the midpoint of the route.

When to use

You need the straight-line distance between two GPS coordinates or cities, e.g. for flight distance, range checks or geofencing.

Do not use when: You need road distance, or ellipsoidal accuracy better than about 0.5 % (use a geodesic method such as Vincenty or Karney on WGS-84); for bearings and compass points use compass-bearing.

Formula

a = sin²(Δφ/2) + cos φ1 · cos φ2 · sin²(Δλ/2); c = 2 · atan2(√a, √(1−a)); d = R · c with R = 6371.0088 km; θ = atan2(sin Δλ · cos φ2, cos φ1 · sin φ2 − sin φ1 · cos φ2 · cos Δλ)

Spherical model with the IUGG mean Earth radius; real distances on the WGS-84 ellipsoid differ by up to about 0.3–0.5 %. The bearing is the initial heading; on long routes it changes continuously along the great circle.

Inputs

ParameterTypeUnitRequiredDescription
lat1number°yesLatitude of point 1 in decimal degrees (north positive, south negative). Range: ≥ -90, ≤ 90
lon1number°yesLongitude of point 1 in decimal degrees (east positive, west negative). Range: ≥ -180, ≤ 180
lat2number°yesLatitude of point 2 in decimal degrees (north positive, south negative). Range: ≥ -90, ≤ 90
lon2number°yesLongitude of point 2 in decimal degrees (east positive, west negative). Range: ≥ -180, ≤ 180

Outputs

OutputTypeUnitDescription
distance_kmnumberkmGreat-circle distance on a sphere of radius 6,371.0088 km.
distance_milesnumbermiSame distance in statute miles (1 mi = 1.609344 km).
distance_nautical_milesnumbernmiSame distance in nautical miles (1 nmi = 1.852 km).
central_angle_degreesnumber°Angle subtended at the Earth's centre.
initial_bearing_degreesnumber°Forward azimuth at point 1, clockwise from true north (0–360).
compass_directionstring16-point compass direction of the initial bearing.
midpoint_latnumber°Latitude of the great-circle midpoint.
midpoint_lonnumber°Longitude of the great-circle midpoint.

Example

Sydney → Tokyo: {"lat1":-33.8688,"lon1":151.2093,"lat2":35.6762,"lon2":139.6503}{"distance_km":7825.83,"distance_miles":4862.74,"distance_nautical_miles":4225.61,"central_angle_degrees":70.3793,"initial_bearing_degrees":350.05,"compass_direction":"N (north)","midpoint_lat":0.9083,"midpoint_lon":145.4933}

Movable Type example: 50°03′59″N 5°42′53″W → 58°38′38″N 3°04′12″W: {"lat1":50.06639,"lon1":-5.71472,"lat2":58.64389,"lon2":-3.07}{"distance_km":968.85,"distance_miles":602.02,"initial_bearing_degrees":9.12,"midpoint_lat":54.3623,"midpoint_lon":-4.5307}

GET https://tttkmbb.com/api/v1/calculate/haversine-distance?lat1=-33.8688&lon1=151.2093&lat2=35.6762&lon2=139.6503

Machine access

Sources

FAQ

How accurate is the haversine formula?

It is exact for a sphere and numerically stable for short distances. Because the Earth is an oblate ellipsoid, results differ from geodesic (Vincenty/Karney) distances by up to about 0.5 %, i.e. roughly 30 km on a 7,800 km flight.

Which sign convention do the coordinates use?

Decimal degrees: north and east positive, south and west negative. Use coordinate-converter to turn degrees-minutes-seconds into decimals first.

Related calculators