How to calculate the distance between two GPS coordinates
Knowing two GPS coordinates is one thing. Knowing how far apart they are — in kilometers, miles, or meters — is often what you actually need. Whether you're planning a hiking route, estimating a flight path, checking the radius of a geofence, or just curious how far two cities really are "as the crow flies," the calculation is the same: the haversine formula. Here's how it works, with worked examples and a link to calculate it instantly.
Straight-line vs. road distance
Before the maths: there are two fundamentally different types of distance between two points on a map.
- Straight-line distance (also called "as the crow flies" or great-circle distance) — the shortest path between two points on the surface of the Earth, ignoring terrain and roads. This is what GPS coordinates give you directly.
- Road distance — the actual driving or walking route, which depends on the road network, can be significantly longer, and requires routing software to calculate.
This article covers straight-line distance. If you need road distance, you need a routing service — but knowing the straight-line distance first gives you a useful sanity check.
The haversine formula explained
The Earth is approximately a sphere. Calculating the shortest path between two points on its surface — a great circle — requires accounting for that curvature. The haversine formula does exactly this. It takes two pairs of latitude/longitude coordinates and returns the central angle between them, which you then multiply by the Earth's radius to get distance.
In pseudocode:
Δlat = lat2 − lat1 (in radians)
Δlng = lng2 − lng1 (in radians)
a = sin²(Δlat/2) + cos(lat1) × cos(lat2) × sin²(Δlng/2)
c = 2 × atan2(√a, √(1−a))
distance = R × c (R = 6371 km)
You can also use our coordinate converter for instant conversions between DMS and decimal degrees — which is the format the formula needs.
Worked example: two cities
Let's calculate the distance between London and New York:
- London:
51.5074° N, 0.1278° W→51.5074, −0.1278 - New York:
40.7128° N, 74.0060° W→40.7128, −74.0060
Converting to radians (multiply by π/180):
- lat1 = 0.8989 rad, lng1 = −0.0022 rad
- lat2 = 0.7101 rad, lng2 = −1.2922 rad
Running through the formula gives a central angle of approximately 0.8803 radians, and multiplying by R = 6371 km gives roughly 5,570 km — consistent with the commonly cited ~5,570 km flight distance between the two cities. Road distance, of course, doesn't exist across the Atlantic, which is why great-circle distance is what aviation uses.
Worked example: two hiking waypoints
For shorter distances the formula is the same, but the numbers are smaller:
- Trailhead:
36.4551, −105.8767 - Summit:
36.5023, −105.8314
The result is approximately 6.8 km straight-line. The actual hiking distance along the trail would likely be 8–12 km depending on terrain, switchbacks, and elevation gain. For route planning, you can sketch a route on the map and see the cumulative distance update in real time.
Converting DMS to decimal degrees first
The haversine formula requires coordinates in decimal degrees. If your coordinates are in degrees, minutes, seconds (DMS) format — like 36° 27' 18.36" N — you need to convert first. The formula is:
decimal = degrees + (minutes / 60) + (seconds / 3600)
So 36° 27' 18.36" N = 36 + 27/60 + 18.36/3600 = 36.4551°. Our coordinate converter handles this instantly in both directions if you'd rather not do it by hand. For the full explanation of the two formats, see decimal degrees vs DMS.
Practical uses for the calculation
- Geofence radius checking — is this point within 500 meters of a reference location? Compare the haversine result to your threshold.
- Proximity alerts — how far is a tagged asset from a fixed point?
- Route planning — sum the haversine distances between sequential waypoints for a rough total distance estimate before walking the route.
- Search radius queries — finding all saved places within 10 km of your current location.
- Flight and shipping planning — great-circle distance is what aviation fuel calculations and cargo routing use.
If you want to go from a distance and bearing to a new coordinate pair (i.e., "start here, travel 5 km north-east, arrive where?"), that's the inverse problem — called the direct geodetic problem — and it's covered by the Vincenty formula. Same idea, more precise for very long distances where the Earth's flattening matters.
Calculate it now
The fastest way to measure the distance between two real points on a map — without doing any maths — is to use the My Location route tool: drop waypoints on both locations and the app shows the straight-line distance between them in real time. Alternatively, use the coordinate converter to prepare your inputs.