Distance
Calculate the exact geodesic distance between two coordinates on the WGS84 ellipsoid. No dataset required — this is a pure geometric calculation.
Request
Section titled “Request”GET /v1/distanceParameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
lat1 | number | Yes | Latitude of point 1 (-90 to 90) |
lng1 | number | Yes | Longitude of point 1 (-180 to 180) |
lat2 | number | Yes | Latitude of point 2 (-90 to 90) |
lng2 | number | Yes | Longitude of point 2 (-180 to 180) |
Example
Section titled “Example”Distance from New York to Los Angeles:
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 .Response
Section titled “Response”{ "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.
Accuracy
Section titled “Accuracy”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).