How to calculate distance between two latitude and longitude

Determining the distance between two geographical points can be crucial for various activities such as navigation, travel planning, and geographic research. In this article, we will explore a popular method for calculating the distance between two latitude and longitude points on Earth’s surface using the Haversine formula.
Haversine Formula
The Haversine formula is an equation that calculates the great-circle distance between two points on the surface of a sphere, such as Earth. It’s particularly useful because it accounts for the Earth’s curved shape. The formula is expressed as:
a = sin²(difference of latitudes/2) + cos(latitude1) * cos(latitude2) * sin²(difference of longitudes/2)
c = 2 * atan2(√a, √(1-a))
distance = R ⋅ c
where,
– latitude1 and latitude2 are the latitudes of the two points,
– difference of latitudes = (latitude2 – latitude1),
– difference of longitudes = (longitude2 – longitude1),
– R is Earth’s radius (mean radius ≈ 6,371 km), and
– atan2(y, x) is an arctangent function which returns the angle whose tangent is y/x.
Step-by-step instructions to calculating distance
1. Convert latitudes and longitudes to radians: Since most geographical coordinates are given in degrees, it’s essential to convert them into radians before proceeding with the formula. To convert from degrees to radians, use ° * π / 180.
2. Compute the differences in latitudes and longitudes: Calculate the difference between each set of coordinates (latitude1 – latitude2) and (longitude1 – longitude2).
3. Calculate `a` using Haversine formula: Compute ‘a’ by following the equation mentioned in Haversine formula.
4. Calculate `c` using atan2 function: Find the arctangent of the square root of ‘a’ divided by the square root of (1-a), multiplied by 2. Use the atan2 function for this operation.
5. Compute the distance: Multiply ‘c’ with Earth’s radius (6,371 km) to obtain the distance between the two geographical points.
Conclusion
The Haversine formula provides an effective method for calculating distances between two latitude and longitude points on Earth’s surface. While it doesn’t offer perfect accuracy due to Earth’s irregular shape, it is still widely used for its simplicity and relatively high precision. Next time you need to measure the distance between geographical locations, remember these steps and apply the Haversine formula for quick and easy calculations.