Computes the great-circle distance between two latitude/longitude points using the haversine formula.
Published for review. The Founder is checking every card himself; anything he strikes comes down the same hour.
Try it
Inputs
lat1 (number, degrees, required) min -90 max 90 : Latitude of point 1.
lon1 (number, degrees, required) min -180 max 180 : Longitude of point 1.
lat2 (number, degrees, required) min -90 max 90 : Latitude of point 2.
lon2 (number, degrees, required) min -180 max 180 : Longitude of point 2.
Outputs
distance_km (km): Great-circle distance between the two points.
Steps
Convert both points' latitudes and longitudes to radians.
Haversine formula: a = sin^2(dLat/2) + cos(lat1)*cos(lat2)*sin^2(dLon/2), where dLat and dLon are the differences in latitude and longitude.
c = 2 * atan2(sqrt(a), sqrt(1-a)).
distance = R * c, where R is the mean Earth radius, 6371.0088 km (IUGG).
Round to 2 decimals.
This treats Earth as a sphere; true geodesic distance on the actual ellipsoid can differ by a small fraction of a percent.
Constants
mean_earth_radius_km = 6371.0088 km (source: Geodetic Reference System 1980 (IUGG mean Earth radius))
Sources
Geodetic Reference System 1980 (IUGG mean Earth radius) (International Union of Geodesy and Geophysics (IUGG), 2026-09-30T19:44:00Z) - Source of the 6371.0088 km IUGG mean Earth radius.