How to calculate the distance between two latitude & longitude
The Haversine formula is like a special math tool that helps us find out how far it is
between two points on a big ball, like the Earth. Imagine you have a big, round ball, and
you want to know how long it would take to go from one point on the ball to another.
Here's what the Haversine formula does:
- Latitude and Longitude: On our Earth-ball, we have imaginary lines called latitude and
longitude. Latitude lines go around the Earth horizontally, and longitude lines go up and
down. These lines help us find any place on the Earth. To use the Haversine formula, we
need to know the latitude and longitude of the two points we want to measure.
- Distance Between Points: Let's say you want to know how far it is from your house (point
A) to your friend's house (point B). The Haversine formula calculates that distance.
- Radius of the Earth: It also needs to know how big the Earth is. Think of the Earth like a
giant ball, and the Haversine formula needs to know how big that ball is. The Earth is
about 6,371 kilometers (or 3,959 miles) wide.
- Haversine Function: This is a special math trick that helps us with the calculation. It's
like a tool in our toolbox that we use to measure the distance. It helps figure out the
angle between the two points on the Earth's surface.
- The Haversine formula then uses all this information to calculate how far it is between
your house and your friend's house. It tells you the distance, like saying it's 10
kilometers or 5 miles.
- So, in simple terms, the Haversine formula is a math tool that tells us how far it is
between two places on our Earth-ball using latitude and longitude. It's like a cool way to
measure distances on our round planet!
Mathematical explanation
- Latitude and Longitude: Each point is represented by its
latitude (φ) and longitude (λ) in degrees. Latitude measures how far north or south a
point is from the equator, and longitude measures how far east or west a point is from the
Prime Meridian.
- Earth's Radius (R):: he formula requires the radius of the
sphere, which is the distance from the center to the surface. The Earth's mean radius is
approximately 6,371 kilometers (or about 3,959 miles).
- Haversine Function: : The Haversine function (haversin) is
used to calculate the central angle (θ) between the two points. The formula for the
Haversine function is:
haversin(θ) = sin²(θ/2)
- Formula: : The Haversine formula calculates the distance
(d) between two points (A and B) on the sphere's surface using the Haversine function and
trigonometric operations:
a = haversin(Δφ) + cos(φ1) * cos(φ2) * haversin(Δλ)
c = 2 * atan2(√a, √(1-a))
d = R * c