geokit/distance

Great-circle distance between two LatLng points.

The haversine formula is used; see https://en.wikipedia.org/wiki/Haversine_formula. Distances are reported in metres using the WGS84 mean Earth radius (6_371_008.8 m). The error against a Vincenty ellipsoidal distance is bounded by 0.5 % for any two points on Earth, which matches every consumer-grade mapping API.

Values

pub fn haversine(a a: latlng.LatLng, b b: latlng.LatLng) -> Float

Great-circle distance between a and b, in metres.

import geokit/distance
import geokit/latlng

let assert Ok(tokyo) = latlng.new(lat: 35.6812, lng: 139.7671)
let assert Ok(osaka) = latlng.new(lat: 34.6937, lng: 135.5023)
distance.haversine(a: tokyo, b: osaka)
// ~= 396_900.0 (≈ 397 km)
pub fn haversine_km(
  a a: latlng.LatLng,
  b b: latlng.LatLng,
) -> Float

Great-circle distance between a and b, in kilometres. Convenience wrapper around haversine.

Search Document