Haversine Formula – Calculate geographic distance on earth



Haversine formula - Calculate geographic distance on earth

Haversine Formula – Calculate geographic distance on earth. If you have two different latitude – longitude values of two different point on earth, then with the help of Haversine Formula, you can easily compute the great-circle distance (The shortest distance between two points on the surface of a Sphere). The term Haversine was coined by Prof. James Inman in 1835. Haversine is very popular and frequently used formula when developing a GIS (Geographic Information System) application or analyzing path and fields.

You can use this Online Route Compass Tool, which calculates the distance based on haversine Formula and also computes the Bearing angle too :

Route Compass Online Tool to Compute Haversine Distance

Haversine formula - Calculate geographic distance on earth
Haversine formula – Calculate geographic distance on earth

Haversine formula:

Central angle Haversine can be computed, between two points with r as radius of earth, d as the distance between two points, \phi_1, \phi_2 is latitude of two points and \lambda_1, \lambda_2 is longitude of two points respectively, as:

\operatorname{haversin}\left(\frac{d}{r}\right) = \operatorname{haversin}(\phi_2 - \phi_1) + \cos(\phi_1) \cos(\phi_2)\operatorname{haversin}(\lambda_2-\lambda_1)

Haversine formula - Calculate geographic distance on earth
Haversine formula – Calculate geographic distance on earth

Law of Haversine:

To derive law of Haversine one needs to start the calculation with spherical law of cosine i.e cos a = cos b * cos c + sin b * sin c * cos A

One can derive Haversine formula to calculate distance between two as:

a = sin²(ΔlatDifference/2) + cos(lat1).cos(lt2).sin²(ΔlonDifference/2)
c = 2.atan2(√a, √(1−a))
d = R.c

where,

ΔlatDifference = lat1 – lat2 (difference of latitude)

ΔlonDifference = lon1 – lon2 (difference of longitude)

R is radius of earth i.e 6371 KM or 3961 miles

and d is the distance computed between two points.

Here is the example result delivered by Haversine Formula:

Lets take one of latitude-longitude for calculation distance,
NEBRASKA, USA (Latitude : 41.507483, longitude : -99.436554) and
KANSAS, USA (Latitude : 38.504048, Longitude : -98.315949)

Do compute the distance with the above written formula. Your answer would be 347.3 Km(kilo-meter). The snapshot demonstrate the same result with map below.

Haversine formula - Calculate geographic distance on earth
Haversine formula – Calculate geographic distance on earth

If you are getting problem in understanding Haversine formula or getting error in the result do comment below. Also if you have more relevant information about the same, do share with us by writing below.

Author: Akshay Upadhyay

Owner and Director of a Private Limited company which serves individual to large scale industries in the field of Maps and GIS. He is a Gold Medalist in M.Tech(Spatial Information Technology) and owns some famous Technology blogs and website... Know more

5 thoughts on “Haversine Formula – Calculate geographic distance on earth”

  1. Thank you for the great website.
    How much error is generated in the bearing calculation as a result of using an average radius of the earth? For coordinates separated by no more than 500 miles, is the Haversine formula the best?
    Thank you,
    Gary

    1. Does anyone have the work shown to further understand the process of navigating these formulas? I’m at a standstill after trying to solve for c.

  2. A submarine cable will be extended between two cities I and J that located on both sides of a sea and have the following geodetic coordinates: I (34°55´N, 56°10´E) J (33°56´N, 130°48´E) R = 3671 km.
    i) The minimum cable length in kilometers. 5
    ii) The direction or azimuth that should be extended this cable from point I.

  3. For excel users, to save you the headache:
    a = (SIN((RADIANS(Lat2-Lat1))/2)^2)+(COS(RADIANS(Lat1))*COS(RADIANS(Lat2))*SIN((RADIANS(Lon2-Lon1))/2)^2)
    c =2*(ATAN2(SQRT(RADIANS(a)),SQRT(1-RADIANS(a))))
    d = 6371*RADIANS(D15)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.