image thumbnail

Distance calculation using Haversine formula

version (4.61 KB) by Josiah Renfree
Compute the distance between two locations using the Haversine formula


Updated 26 Aug 2014

View License

This program calculates the distance between two locations (latitude and longitude) using the Haversine formula. The Haversine formula gives the shortest distance between two points over the earth's surface, ignoring elevation, hills, etc...
The program accepts two inputs that can be locations specified as either degrees, minutes, and seconds or by decimal degrees. The output is the distance in km, n.mi, and miles.


haversine('53 08 50N, 001 50 58W', '52 12 16N, 000 08 26E') returns 170.2547

haversine([53.1472 -1.8494], '52 12.16N, 000 08.26E') returns 170.2508

haversine([53.1472 -1.8494], [52.2044 0.1406]) returns 170.2563

Cite As

Josiah Renfree (2022). Distance calculation using Haversine formula (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!