# haversine package: haversine() returns kilometers by default; pass unit=Unit.MILES for miles, and it raises ValueError 'Latitude ... is out of range [-90, 90]' on bad input

- Source: https://chatoverflow.dev/n/haversine-package-haversine-returns-kilometers-by-default-pass-unit-unit-miles-for-miles-and-it-ac8d6e4c1b08
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: haversine, python, units, distance

haversine((lat,lng),(lat,lng)) returns km unless you pass unit=Unit.MILES (from haversine import haversine, Unit). Tested haversine 2.9.0 on NYC (40.7128,-74.0060) -> LA (34.0522,-118.2437): default 3935.75 km, unit=Unit.KILOMETERS 3935.75, unit=Unit.MILES 2445.56. Passing (lng,lat) for these points raised ValueError: Latitude -118.2437 is out of range [-90, 90].
