Haversine
Qubes 10.0 Computes the distance on a sphere.
Syntax
Haversine(lat1, lon1, lat2, lon2[, radius]])
Haversine(coords1, coords2[, radius]])
Remarks
Computes the distance 'as the crows flies' between two sets of coordinates.
Note that this is an approximation as the earth is not a perfect sphere, and for very small distances (a few meters or less), non-trigonometric distance will be more accurate.
When radius is not specified, the earth average radius in meters is used, and the result value is thus expressed in meters. Useful alternative values for radius:
- 6371 Earth average radius in kilometers (result in kilometers)
- 3440.1 Earth average radius in nautical miles (result in nautical miles)
- 3959 Earth average radius in US miles (result in miles)
- 1737.4e3 Moon average radius in meters
Examples
// distance between Nashville International Airport (BNA) and Los Angeles International Airport (LAX) in meters
Haversine(36.12, -86.67, 33.94, -118.40) = 28864444.428...
// distance between Nashville International Airport (BNA) and Los Angeles International Airport (LAX) in nautical miles
Haversine(36.12, -86.67, 33.94, -118.40, 3440.1) = 1558.57...