Distance API
Calculate great-circle distances locally from coordinates supplied by your application. The API uses Turf.js and has no provider, external calculation API, dataset, or fallback. Requests are authenticated and stateless. Coordinates are not saved.
Authentication and setup
Every endpoint requires x-app-id and x-api-key. Distance does not require x-provider-key. See Setup and authentication for credential handling. For a local development credential, set NODE_ENV=development, configure the existing database, and run this from the repository root:
npm run app -- seed-dev
Copy the printed postman API key. It is shown only once. To issue another for an existing development app, run npm run app -- issue postman. Use the registered slug as x-app-id and the complete printed <credential-id>.<secret> as x-api-key.
All requests are POST with Content-Type: application/json. No endpoint uses path or query parameters. Every response is wrapped by the standard API envelope. Successful calculation data is under data, with statusCode, message, and timestamp alongside it.
curl --request POST 'http://localhost:8000/distance/calculate' \
--header 'Content-Type: application/json' \
--header 'x-app-id: postman' \
--header 'x-api-key: <credential-id>.<secret>' \
--data '{"from":{"lat":14.5995,"lon":120.9842},"to":{"lat":14.6042,"lon":120.9822},"units":"meters"}'
Coordinate and unit rules
Coordinates use decimal degree { "lat": number, "lon": number } objects. Latitude is from -90 through 90. Longitude is from -180 through 180. Distances and radii use kilometers by default. meters and miles are also supported. Bearings are decimal degrees from -180 through 180, with positive values clockwise from true north.
POST /distance/calculate
Measures the great-circle distance between from and to.
Required headers are Content-Type: application/json, x-app-id, and x-api-key. There are no path or query parameters. The body requires from and to coordinate objects. units is optional and accepts kilometers, meters, or miles.
curl --request POST 'http://localhost:8000/distance/calculate' \
--header 'Content-Type: application/json' \
--header 'x-app-id: postman' \
--header 'x-api-key: <credential-id>.<secret>' \
--data '{
"from": { "lat": 0, "lon": 0 },
"to": { "lat": 0, "lon": 1 },
"units": "kilometers"
}'
HTTP 200 response body:
{"statusCode":200,"message":"Success","data":{"distance":111.1950802335329,"units":"kilometers"},"timestamp":"<ISO-8601 timestamp>"}
POST /distance/batch
Measures up to 100 coordinate pairs. Results match the pairs input order. Body requires pairs, an array of { "from": coordinate, "to": coordinate } objects. Optional units accepts kilometers, meters, or miles.
curl --request POST 'http://localhost:8000/distance/batch' \
--header 'Content-Type: application/json' \
--header 'x-app-id: postman' \
--header 'x-api-key: <credential-id>.<secret>' \
--data '{
"pairs": [
{ "from": { "lat": 0, "lon": 0 }, "to": { "lat": 0, "lon": 1 } },
{ "from": { "lat": 0, "lon": 0 }, "to": { "lat": 0, "lon": 0 } }
]
}'
HTTP 200 response body:
{"statusCode":200,"message":"Success","data":{"distances":[111.1950802335329,0],"units":"kilometers"},"timestamp":"<ISO-8601 timestamp>"}
POST /distance/nearest
Ranks up to 500 candidate coordinates by distance from origin. The body requires origin and candidates. Optional limit is an integer from 1 to 500 and defaults to 1. Optional units accepts kilometers, meters, or miles. Each result contains the original zero-based input index, coordinate, and distance. Equal distances retain input order.
curl --request POST 'http://localhost:8000/distance/nearest' \
--header 'Content-Type: application/json' \
--header 'x-app-id: postman' \
--header 'x-api-key: <credential-id>.<secret>' \
--data '{
"origin": { "lat": 0, "lon": 0 },
"candidates": [{ "lat": 0, "lon": 0.02 }, { "lat": 0, "lon": 0.01 }],
"limit": 1,
"units": "meters"
}'
HTTP 200 response body:
{"statusCode":200,"message":"Success","data":{"results":[{"index":1,"coordinate":{"lat":0,"lon":0.01},"distance":1111.950802335329}],"units":"meters"},"timestamp":"<ISO-8601 timestamp>"}
POST /distance/within-radius
Finds candidates at or within an inclusive radius from origin. The body requires origin, candidates (up to 500 coordinates), and non-negative radius. Optional units accepts kilometers, meters, or miles. Results include each original index, coordinate, and distance, in input order. An empty candidate list or no matches returns an empty array.
curl --request POST 'http://localhost:8000/distance/within-radius' \
--header 'Content-Type: application/json' \
--header 'x-app-id: postman' \
--header 'x-api-key: <credential-id>.<secret>' \
--data '{
"origin": { "lat": 0, "lon": 0 },
"candidates": [{ "lat": 0, "lon": 0.02 }, { "lat": 0, "lon": 0.01 }],
"radius": 1500,
"units": "meters"
}'
HTTP 200 response body:
{"statusCode":200,"message":"Success","data":{"results":[{"index":1,"coordinate":{"lat":0,"lon":0.01},"distance":1111.950802335329}],"units":"meters"},"timestamp":"<ISO-8601 timestamp>"}
POST /distance/bearing
Returns the initial bearing clockwise from true north. The body requires distinct from and to coordinate objects. Coincident coordinates return 400 with code DISTANCE_BEARING_UNDEFINED. Antipodal coordinates return 400 with code DISTANCE_ANTIPODAL_POINTS because the shortest path has no unique bearing.
curl --request POST 'http://localhost:8000/distance/bearing' \
--header 'Content-Type: application/json' \
--header 'x-app-id: postman' \
--header 'x-api-key: <credential-id>.<secret>' \
--data '{
"from": { "lat": 0, "lon": 0 },
"to": { "lat": 0, "lon": 1 }
}'
HTTP 200 response body:
{"statusCode":200,"message":"Success","data":{"bearing":90},"timestamp":"<ISO-8601 timestamp>"}
POST /distance/destination
Projects a coordinate from origin along a bearing. The body requires origin, non-negative distance, and bearing between -180 and 180 degrees. Optional units accepts kilometers, meters, or miles.
curl --request POST 'http://localhost:8000/distance/destination' \
--header 'Content-Type: application/json' \
--header 'x-app-id: postman' \
--header 'x-api-key: <credential-id>.<secret>' \
--data '{
"origin": { "lat": 0, "lon": 0 },
"distance": 111.1950802335329,
"bearing": 90,
"units": "kilometers"
}'
HTTP 200 response body:
{"statusCode":200,"message":"Success","data":{"coordinate":{"lat":6.122923126514857e-17,"lon":1}},"timestamp":"<ISO-8601 timestamp>"}
POST /distance/midpoint
Returns the coordinate halfway along the shortest great-circle path between from and to. Antipodal coordinates return 400 with code DISTANCE_ANTIPODAL_POINTS because they have no unique midpoint.
curl --request POST 'http://localhost:8000/distance/midpoint' \
--header 'Content-Type: application/json' \
--header 'x-app-id: postman' \
--header 'x-api-key: <credential-id>.<secret>' \
--data '{
"from": { "lat": 0, "lon": 0 },
"to": { "lat": 0, "lon": 2 }
}'
HTTP 200 response body:
{"statusCode":200,"message":"Success","data":{"coordinate":{"lat":6.122923126514857e-17,"lon":1}},"timestamp":"<ISO-8601 timestamp>"}
Errors and rate limits
Invalid JSON fields, out-of-range coordinates, unsupported units, and arrays over their limits return HTTP 400 Bad Request. Invalid or missing app credentials return 401 Unauthorized. Undefined bearings and antipodal paths include their specific code in the standard error response.
The seven routes share 1,000 requests per rolling 60 seconds per authenticated application. Each batch request uses one request from that quota. A separate pre-authentication limit allows up to 1,200 requests per client IP per minute across routes. A quota rejection returns 429 Too Many Requests, code RATE_LIMIT_EXCEEDED, and Retry-After in seconds. Successful rate-limited responses include X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Window, and X-RateLimit-Reset. See the rate-limiting guide.
Use cases
- Rider shortlisting: rank rider coordinates around a pickup using
/distance/nearest. - Delivery coverage and service availability: check whether a customer is within range of a depot or service location using
/distance/within-radius. - Nearby establishments: filter your own list of stores, clinics, or venues by a radius around the supplied coordinate.
- Attendance radius validation: compare a check-in coordinate with the approved site in meters and accept it when its distance is within the configured radius.
Coordinates and the calculation result are processed in memory. The API does not look up, retain, or enrich the supplied locations.