Route matrix
Times and distances between every rider and every order in one request: the building block of dispatch.
On this page
The travel time and distance from each of several origins to each of several destinations, in one request: every rider to every order, every warehouse to every customer. The building block of dispatch, batching and delivery zones.
Ask for a matrix
curl -X POST "https://nways.ng/maps/v1/routes/matrix?key=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"origins": [{"lat": 6.6018, "lng": 3.3515}, {"lat": 6.5005, "lng": 3.3581}], "destinations": [{"lat": 6.5965, "lng": 3.3421}, {"lat": 6.4413, "lng": 3.4250}], "mode": "dispatch"}'import { createClient } from '@nways/maps'
const nways = createClient({ key: 'YOUR_API_KEY' })
const { elements } = await nways.matrix({
origins: [{ lat: 6.6018, lng: 3.3515 }, { lat: 6.5005, lng: 3.3581 }],
destinations: [{ lat: 6.5965, lng: 3.3421 }, { postcode: 'LA08A09DB09' }],
mode: 'dispatch',
})| Field | Description |
|---|---|
origins, destinations | Required. 1 to 50 each, and at most 625 pairs (origins × destinations). Each is { lat, lng }, { postcode } (a NIPOST building’s best entrance), { ghanaPost } or { plusCode }. |
mode | drive (default), van, okada, keke and danfo (keeping to their bans, as Routes does), motorbike and dispatch (couriers’ bikes: only bans on every motorcycle apply), walk or bicycle. |
The answer’s elements has one entry per pair: originIndex, destinationIndex, durationS, distanceM, and status (OK; ROUTE_NOT_FOUND when there’s no way between them; NOT_ALLOWED when the mode is banned at either end, with the ban). Points more than 400 km apart by car (200 km otherwise) are refused with MATRIX_TOO_FAR. Reference
Okadas, kekes and danfos keep to their ban areas: a pair from or to a ban area comes back NOT_ALLOWED, with the ban. To rank your own couriers’ bikes, which only need to keep off roads closed to every motorcycle, use dispatch.
Billing
A matrix is billed per element (pair): 2 origins × 2 destinations is 4. Rate limits count elements too: 3,000 a minute per key by default. Pricing
See it in use
The dispatch sample gives each new order to the rider who can reach it first.