Ad Space — Top Banner

Haversine Formula

Reference for the Haversine formula calculating great-circle distance between two lat/lon coordinates on Earth.
Used in GPS, flight, and mapping apps.

The Formula

a = sin²(Δφ/2) + cos(φ₁) × cos(φ₂) × sin²(Δλ/2)
d = 2R × arcsin(√a)

The Haversine formula calculates the shortest distance between two points on a sphere using their latitude and longitude. It accounts for the curvature of the Earth and is accurate for most practical purposes.

Calculator

Variables

SymbolMeaning
dDistance between the two points (km or miles)
RRadius of Earth (6,371 km or 3,959 miles)
φ₁, φ₂Latitude of point 1 and point 2 (in radians)
λ₁, λ₂Longitude of point 1 and point 2 (in radians)
ΔφDifference in latitude (φ₂ - φ₁)
ΔλDifference in longitude (λ₂ - λ₁)

Example 1

Distance from New York (40.7128°N, 74.0060°W) to London (51.5074°N, 0.1278°W)

Convert to radians: φ₁ = 0.7106, φ₂ = 0.8989, λ₁ = -1.2918, λ₂ = -0.00223

Δφ = 0.1883, Δλ = 1.2896

a = sin²(0.0942) + cos(0.7106) × cos(0.8989) × sin²(0.6448)

a = 0.00886 + 0.7602 × 0.6270 × 0.3620 = 0.1814

d = 2 × 6371 × arcsin(√0.1814) ≈ 5,570 km

Example 2

Distance from Tokyo (35.6762°N, 139.6503°E) to Sydney (33.8688°S, 151.2093°E)

Δφ = 69.545° = 1.2137 rad, Δλ = 11.559° = 0.2018 rad

Computing the haversine components and summing:

d ≈ 7,823 km

When to Use It

Use the Haversine formula when:

  • Calculating distances between GPS coordinates
  • Building location-based apps and services
  • Planning flight routes or shipping distances
  • Finding the nearest point of interest from a given location

Key Notes

  • Formula: a = sin²(Δlat/2) + cos(lat₁)·cos(lat₂)·sin²(Δlon/2); distance d = 2R·arcsin(√a) where R ≈ 6,371 km is Earth's mean radius. Coordinates must be in radians for the trigonometric functions.
  • Gives great-circle distance: The haversine computes the shortest path along Earth's surface (a great circle), not the straight-line through-Earth distance. This is the relevant distance for navigation, flight routing, and any path that follows the surface.
  • Numerically stable for short distances: The alternative spherical law of cosines (d = R·arccos(sinφ₁sinφ₂ + cosφ₁cosφ₂cosΔλ)) loses precision for short distances due to floating-point cancellation near arccos(1). Haversine avoids this problem by using squared sines.
  • Earth is not a perfect sphere: Earth is an oblate spheroid (flattened at poles, R_equatorial ≈ 6,378 km vs R_polar ≈ 6,357 km). Haversine uses a single mean radius and has error up to ~0.5%. For survey-grade accuracy, use the Vincenty formula which accounts for ellipticity.
  • Applications: Haversine is used in GPS and mapping software (Google Maps, OpenStreetMap), flight distance calculation, geofencing, ride-sharing nearest-driver matching, and any location-based service requiring great-circle distance.

Ad Space — Bottom Banner

Embed This Calculator

Copy the code below and paste it into your website or blog.
The calculator will work directly on your page.