Skip to content

Distance

Calculate the exact geodesic distance between two coordinates on the WGS84 ellipsoid. No dataset required — this is a pure geometric calculation.

GET /v1/distance
ParameterTypeRequiredDescription
lat1numberYesLatitude of point 1 (-90 to 90)
lng1numberYesLongitude of point 1 (-180 to 180)
lat2numberYesLatitude of point 2 (-90 to 90)
lng2numberYesLongitude of point 2 (-180 to 180)

Distance from New York to Los Angeles:

Terminal window
curl -s "https://api.terranode.co/v1/distance?lat1=40.7128&lng1=-74.006&lat2=34.0522&lng2=-118.2437" \
-H "x-api-key: YOUR_API_KEY" | jq .
{
"distance_m": 3944422.2,
"distance_mi": 2450.95,
"latency_ms": 96,
"api_version": "v1",
"semantics_version": "0.1.0"
}

Note: The API returns meters and miles. To get kilometers, divide distance_m by 1000.

Uses Karney’s algorithm on the WGS84 ellipsoid — the same math as PostGIS ST_Distance_Spheroid. Sub-nanometer precision. This is an exact geodesic calculation, not the Haversine approximation (which has ~0.3% error).