Percursos
Percursos para cada forma de viajar, a matriz de percursos e a otimização de rotas.
Nesta página
Envie a sua chave com key=A_SUA_CHAVE_API no endereço, ou no cabeçalho X-NWays-Api-Key. Chaves de API
Endereço base: https://nways.ng/maps/v1
Um percurso, com até 25 pontos intermédios
POST https://nways.ng/maps/v1/routes/compute
Automóvel, carrinha, okada (mototáxi; respeita as proibições de okada, faz a pé a passagem do limite de uma zona proibida), motorbike (a sua própria mota) e dispatch (motas de estafetas: isentas das proibições de okada de passageiros), keke e danfo (respeitam as suas proibições), a pé, bicicleta, barco (barcos de passageiros e cais) e comboio. Os códigos postais encaminham para a melhor entrada do edifício; onde a estrada acaba antes da porta, o percurso indica onde parar e como terminar (lastMile); portagens nas respetivas moedas, passagens de fronteira, condomínios fechados, proibições evitadas com as suas fontes. fields= escolhe os campos de cada percurso. Motivos: MODE_INVALID, LANG_INVALID, ROUTING_PREFERENCE_INVALID, TOO_MANY_INTERMEDIATES, INTERMEDIATES_NOT_SUPPORTED, AVOID_INVALID, TOLL_VEHICLE_INVALID, LAST_MILE_INVALID, ACCESS_INVALID, WAYPOINT_INVALID, POSTCODE_INVALID, POSTCODE_NOT_FOUND, GHANAPOST_INVALID, GHANAPOST_NOT_FOUND, PLUSCODE_INVALID, NO_ROUTE, NO_ROAD_ROUTE, ROUTE_TOO_FAR, ROUTING_UNAVAILABLE, OKADA_BANNED_ORIGIN, OKADA_BANNED_DESTINATION, OKADA_BANNED_ROUTE, KEKE_BANNED_*, DANFO_BANNED_*, MOTORBIKE_BANNED_*, ROUTING_UNAVAILABLE (503).
Parâmetros
| Nome | Onde | Tipo | Descrição |
|---|---|---|---|
fields | consulta | string | Lista separada por vírgulas dos campos a manter em cada resultado (a.b entra em objetos; id é sempre mantido; * = todos). |
Corpo do pedido
| Campo | Tipo | Descrição |
|---|---|---|
origin | Waypoint | Obrigatório. Exatamente um de: lat e lng, postcode (NIPOST: encaminha para a sua melhor entrada), ghanaPost ou plusCode (completo, ou curto com uma localidade a seguir). |
origin.lat | number | |
origin.lng | number | |
origin.postcode | string | |
origin.ghanaPost | string | |
origin.plusCode | string | |
origin.heading | number | Só na origem: sentido de deslocação (graus), para que um veículo em movimento não comece com uma inversão de marcha. |
destination | Waypoint | Obrigatório. Exatamente um de: lat e lng, postcode (NIPOST: encaminha para a sua melhor entrada), ghanaPost ou plusCode (completo, ou curto com uma localidade a seguir). |
destination.lat | number | |
destination.lng | number | |
destination.postcode | string | |
destination.ghanaPost | string | |
destination.plusCode | string | |
destination.heading | number | Só na origem: sentido de deslocação (graus), para que um veículo em movimento não comece com uma inversão de marcha. |
intermediates | Waypoint[] | No máximo 25 elementos. |
intermediates[].lat | number | |
intermediates[].lng | number | |
intermediates[].postcode | string | |
intermediates[].ghanaPost | string | |
intermediates[].plusCode | string | |
intermediates[].heading | number | Só na origem: sentido de deslocação (graus), para que um veículo em movimento não comece com uma inversão de marcha. |
mode | string | Um de: drive, van, okada, motorbike, dispatch, keke, danfo, walk, bicycle, boat, train. Predefinição: drive. |
alternatives | boolean | Até 2 percursos adicionais (sem pontos intermédios). Predefinição: false. |
routingPreference | string | Um de: traffic_unaware, traffic_aware. Predefinição: traffic_unaware. |
departAt | string (date-time) | |
avoid | string[] | |
lang | string | Um de: en, fr, pt. |
tollVehicle | string | Classe tarifária de portagem (van: autocarro). Um de: car, suv, bus, truck. |
access | string | Viagens de comboio e barco: de e para estações e cais. Um de: walk, okada, drive. |
lastMile | string | Um de: walk, okada. |
allowBans | string[] | Ids de proibições não confirmadas (de unconfirmedBans) por onde passar mesmo assim. |
fares | boolean | Acrescentar estimativas de tarifa a cada percurso (SKU avançado). Predefinição: false. |
curl -X POST "https://nways.ng/maps/v1/routes/compute" \
-H "X-NWays-Api-Key: A_SUA_CHAVE_API" \
-H "Content-Type: application/json" \
-d '{"origin":{"lat":6.4474,"lng":3.472},"destination":{"postcode":"LA08A09DB10"},"mode":"drive","routingPreference":"traffic_aware"}'const res = await fetch('https://nways.ng/maps/v1/routes/compute', {
method: 'POST',
headers: { 'X-NWays-Api-Key': process.env.NWAYS_API_KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({
"origin": {
"lat": 6.4474,
"lng": 3.472
},
"destination": {
"postcode": "LA08A09DB10"
},
"mode": "drive",
"routingPreference": "traffic_aware"
}),
})
const data = await res.json()import os
import requests
res = requests.post(
"https://nways.ng/maps/v1/routes/compute",
headers={"X-NWays-Api-Key": os.environ["NWAYS_API_KEY"]},
json={"origin": {"lat": 6.4474, "lng": 3.472}, "destination": {"postcode": "LA08A09DB10"}, "mode": "drive", "routingPreference": "traffic_aware"},
timeout=10,
)
data = res.json()Resposta
Percursos
| Campo | Tipo | Descrição |
|---|---|---|
routes | Route[] | Obrigatório. |
routes[].distanceM | number | Obrigatório. |
routes[].durationS | number | Obrigatório. |
routes[].staticDurationS | number | Obrigatório. Sem trânsito em direto |
routes[].trafficDelayS | number | Obrigatório. O que o trânsito e os incidentes acrescentam agora (traffic_aware). |
routes[].speedSource | string | Um de: live, typical, estimated. |
routes[].summary | string | |
routes[].geometry | LineString | Obrigatório. |
routes[].geometry.type | string | Obrigatório. |
routes[].geometry.coordinates | number[][] | Obrigatório. |
routes[].legs | Leg[] | Obrigatório. Um por troço entre paragens. |
routes[].legs[].distanceM | number | Obrigatório. |
routes[].legs[].durationS | number | Obrigatório. |
routes[].steps | Step[] | Obrigatório. |
routes[].steps[].maneuver | string | Obrigatório. depart, arrive, continue, left, right, slight_left, sharp_right, uturn_left, roundabout_enter, ferry_enter, … (outros) |
routes[].steps[].instruction | string | Obrigatório. |
routes[].steps[].distanceM | number | Obrigatório. |
routes[].steps[].durationS | number | Obrigatório. |
routes[].steps[].streetNames | string[] | |
routes[].steps[].startIndex | integer | Obrigatório. Índice em geometry.coordinates |
routes[].steps[].endIndex | integer | Obrigatório. |
routes[].steps[].roundaboutExit | integer | |
routes[].steps[].toward | string[] | |
routes[].steps[].atTrafficLight | boolean | |
routes[].steps[].crossing | string | A pé: passagem superior, passagem inferior, passadeira, semáforos, travessia, cruzamento |
routes[].segments | object[] | Viagens que mudam a forma de deslocação (comboio, barco, okada com um trajeto a pé para passar uma proibição). |
routes[].segments[].mode | string | Obrigatório. Um de: walk, okada, drive, train, boat. |
routes[].segments[].line | string | |
routes[].segments[].from | string | Obrigatório. |
routes[].segments[].to | string | Obrigatório. |
routes[].segments[].distanceM | number | Obrigatório. |
routes[].segments[].durationS | number | Obrigatório. |
routes[].segments[].waitS | number | |
routes[].segments[].stops | integer | |
routes[].segments[].scheduled | boolean | |
routes[].segments[].estimated | boolean | |
routes[].segments[].fare | string | |
routes[].segments[].note | string | |
routes[].segments[].geometry | LineString | Obrigatório. |
routes[].segments[].geometry.type | string | Obrigatório. |
routes[].segments[].geometry.coordinates | number[][] | Obrigatório. |
routes[].congestion | object[] | |
routes[].congestion[].startIndex | integer | |
routes[].congestion[].endIndex | integer | |
routes[].congestion[].level | string | |
routes[].tolls | object | |
routes[].tolls.gates | object[] | |
routes[].tolls.gates[].name | string | |
routes[].tolls.gates[].location | Point | |
routes[].tolls.gates[].atM | integer | |
routes[].tolls.gates[].price | integer | null | |
routes[].tolls.gates[].currency | string | |
routes[].tolls.gates[].payment | string | |
routes[].tolls.total | object | |
routes[].tolls.unknownPrices | integer | |
routes[].borderCrossings | object[] | |
routes[].borderCrossings[].from | string | |
routes[].borderCrossings[].to | string | |
routes[].borderCrossings[].location | Point | |
routes[].borderCrossings[].location.type | string | Obrigatório. |
routes[].borderCrossings[].location.coordinates | number[] | Obrigatório. [lng, lat] Pelo menos 2 elementos, no máximo 2 elementos. |
routes[].borderCrossings[].atM | integer | |
routes[].borderCrossings[].post | string | |
routes[].borderCrossings[].clockChangeH | number | |
routes[].vehicleRules | object | Viagens de okada, keke e danfo |
routes[].vehicleRules.vehicle | string | Um de: okada, motorbike, keke, danfo. |
routes[].vehicleRules.avoided | Ban[] | |
routes[].vehicleRules.avoided[].id | string | Obrigatório. |
routes[].vehicleRules.avoided[].zone | string | Obrigatório. |
routes[].vehicleRules.avoided[].scope | string | Obrigatório. |
routes[].vehicleRules.avoided[].hours | string | |
routes[].vehicleRules.avoided[].since | string | |
routes[].vehicleRules.avoided[].source | string (uri) | |
routes[].vehicleRules.avoided[].where | string | Um de: origin, destination, stop, route. |
routes[].vehicleRules.avoided[].walkM | number | |
routes[].vehicleRules.advice | Ban[] | |
routes[].vehicleRules.advice[].id | string | Obrigatório. |
routes[].vehicleRules.advice[].zone | string | Obrigatório. |
routes[].vehicleRules.advice[].scope | string | Obrigatório. |
routes[].vehicleRules.advice[].hours | string | |
routes[].vehicleRules.advice[].since | string | |
routes[].vehicleRules.advice[].source | string (uri) | |
routes[].vehicleRules.advice[].where | string | Um de: origin, destination, stop, route. |
routes[].vehicleRules.advice[].walkM | number | |
routes[].vehicleRules.endBan | Ban | |
routes[].vehicleRules.endBan.id | string | Obrigatório. |
routes[].vehicleRules.endBan.zone | string | Obrigatório. |
routes[].vehicleRules.endBan.scope | string | Obrigatório. |
routes[].vehicleRules.endBan.hours | string | |
routes[].vehicleRules.endBan.since | string | |
routes[].vehicleRules.endBan.source | string (uri) | |
routes[].vehicleRules.endBan.where | string | Um de: origin, destination, stop, route. |
routes[].vehicleRules.endBan.walkM | number | |
routes[].vehicleRules.allowedByRequest | Ban[] | |
routes[].vehicleRules.allowedByRequest[].id | string | Obrigatório. |
routes[].vehicleRules.allowedByRequest[].zone | string | Obrigatório. |
routes[].vehicleRules.allowedByRequest[].scope | string | Obrigatório. |
routes[].vehicleRules.allowedByRequest[].hours | string | |
routes[].vehicleRules.allowedByRequest[].since | string | |
routes[].vehicleRules.allowedByRequest[].source | string (uri) | |
routes[].vehicleRules.allowedByRequest[].where | string | Um de: origin, destination, stop, route. |
routes[].vehicleRules.allowedByRequest[].walkM | number | |
routes[].vehicleRules.reported | object[] | |
routes[].vehicleRules.reported[].location | Point | |
routes[].vehicleRules.reported[].reporters | integer | |
routes[].vehicleRules.reported[].lastSeen | string | |
routes[].lastMile | object | |
routes[].lastMile.stopAt | Point | |
routes[].lastMile.stopAt.type | string | Obrigatório. |
routes[].lastMile.stopAt.coordinates | number[] | Obrigatório. [lng, lat] Pelo menos 2 elementos, no máximo 2 elementos. |
routes[].lastMile.stopName | string | |
routes[].lastMile.mode | string | |
routes[].lastMile.distanceM | number | |
routes[].lastMile.durationS | number | |
routes[].lastMile.geometry | LineString | |
routes[].lastMile.geometry.type | string | Obrigatório. |
routes[].lastMile.geometry.coordinates | number[][] | Obrigatório. |
routes[].access | object | |
routes[].access.kind | string | Um de: estate, government, military, police, gate. |
routes[].access.text | string | |
routes[].access.name | string | |
routes[].access.gate | Point | |
routes[].access.gate.type | string | Obrigatório. |
routes[].access.gate.coordinates | number[] | Obrigatório. [lng, lat] Pelo menos 2 elementos, no máximo 2 elementos. |
routes[].access.dropOffAtGate | boolean | |
routes[].roadCondition | object | |
routes[].roadCondition.roughM | number | |
routes[].country | string | |
routes[].warnings | string[] | |
routes[].fares | FareEstimate[] | |
routes[].fares[].mode | string | Obrigatório. Um de: taxi, shared_taxi, okada, keke, bus, ridehail, boat. |
routes[].fares[].service | string | |
routes[].fares[].currency | string | Obrigatório. Um de: NGN, GHS, XOF. |
routes[].fares[].low | integer | Obrigatório. |
routes[].fares[].typical | integer | Obrigatório. |
routes[].fares[].high | integer | Obrigatório. |
routes[].fares[].text | string | Obrigatório. |
routes[].fares[].perPerson | boolean | Obrigatório. |
routes[].fares[].charter | boolean | Obrigatório. |
routes[].fares[].night | boolean | |
routes[].fares[].rush | boolean | |
routes[].fares[].rain | boolean | |
routes[].fares[].basis | string | Obrigatório. Um de: crowd, guide. |
routes[].fares[].reports | integer | Obrigatório. |
routes[].fares[].durationS | number | Obrigatório. |
routes[].fares[].openingOffer | integer | Onde os preços se regateiam: uma boa primeira oferta. |
routes[].fares[].sources | string (uri)[] | |
waypoints | object[] | Obrigatório. Para onde cada ponto de passagem foi encaminhado, por ordem. |
waypoints[].location | Point | Obrigatório. |
waypoints[].location.type | string | Obrigatório. |
waypoints[].location.coordinates | number[] | Obrigatório. [lng, lat] Pelo menos 2 elementos, no máximo 2 elementos. |
waypoints[].postcode | string | |
waypoints[].entrance | string | |
mode | string | Obrigatório. Um de: drive, van, okada, motorbike, dispatch, keke, danfo, walk, bicycle, boat, train. Predefinição: drive. |
warnings | string[] | |
unconfirmedBans | Ban[] | |
unconfirmedBans[].id | string | Obrigatório. |
unconfirmedBans[].zone | string | Obrigatório. |
unconfirmedBans[].scope | string | Obrigatório. |
unconfirmedBans[].hours | string | |
unconfirmedBans[].since | string | |
unconfirmedBans[].source | string (uri) | |
unconfirmedBans[].where | string | Um de: origin, destination, stop, route. |
unconfirmedBans[].walkM | number | |
attribution | string | Obrigatório. |
{
"routes": [
{
"distanceM": 0,
"durationS": 0,
"staticDurationS": 0,
"trafficDelayS": 0,
"speedSource": "live",
"summary": "Admiralty Way and Awudu Ekpekha Boulevard",
"geometry": {
"type": "string",
"coordinates": [
[]
]
},
"legs": [
{
"distanceM": 0,
"durationS": 0
}
],
"steps": [
{
"maneuver": "right",
"instruction": "Turn right onto Admiralty Way.",
"distanceM": 0,
"durationS": 0,
"streetNames": [],
"startIndex": 0,
"endIndex": 0,
"roundaboutExit": 0,
"toward": [],
"atTrafficLight": true,
"crossing": "string"
}
],
"segments": [
{
"mode": "walk",
"line": "string",
"from": "string",
"to": "string",
"distanceM": 0,
"durationS": 0,
"waitS": 0,
"stops": 0,
"scheduled": true,
"estimated": true,
"fare": "string",
"note": "string",
"geometry": {}
}
],
"congestion": [
{
"startIndex": 0,
"endIndex": 0,
"level": "string"
}
],
"tolls": {
"gates": [
{}
],
"total": {
"NGN": 300
},
"unknownPrices": 0
},
"borderCrossings": [
{
"from": "string",
"to": "string",
"location": {},
"atM": 0,
"post": "string",
"clockChangeH": 0
}
],
"vehicleRules": {
"vehicle": "okada",
"avoided": [
{}
],
"advice": [
{}
],
"endBan": {
"id": "string",
"zone": "Third Mainland Bridge",
"scope": "string",
"hours": "string",
"since": "string",
"source": "string",
"where": "origin",
"walkM": 0
},
"allowedByRequest": [
{}
],
"reported": [
{}
]
},
"lastMile": {
"stopAt": {
"type": "string",
"coordinates": []
},
"stopName": "string",
"mode": "string",
"distanceM": 0,
"durationS": 0,
"geometry": {
"type": "string",
"coordinates": []
}
},
"access": {
"kind": "estate",
"text": "string",
"name": "string",
"gate": {
"type": "string",
"coordinates": []
},
"dropOffAtGate": true
},
"roadCondition": {
"roughM": 0
},
"country": "string",
"warnings": [
"string"
],
"fares": [
{
"mode": "taxi",
"service": "Bolt",
"currency": "NGN",
"low": 0,
"typical": 0,
"high": 0,
"text": "₦3,000–4,500",
"perPerson": true,
"charter": true,
"night": true,
"rush": true,
"rain": true,
"basis": "crowd",
"reports": 0,
"durationS": 0,
"openingOffer": 0,
"sources": []
}
]
}
],
"waypoints": [
{
"location": {
"type": "string",
"coordinates": [
0
]
},
"postcode": "string",
"entrance": "string"
}
],
"mode": "drive",
"warnings": [
"string"
],
"unconfirmedBans": [
{
"id": "string",
"zone": "Third Mainland Bridge",
"scope": "string",
"hours": "string",
"since": "string",
"source": "string",
"where": "origin",
"walkM": 0
}
],
"attribution": "string"
}Erros
defaultErro
Tempos de viagem de muitas origens para muitos destinos (por elemento)
POST https://nways.ng/maps/v1/routes/matrix
Até 50 origens e 50 destinos, 625 elementos (origens × destinos), cada um faturado como uma unidade route_matrix. Modos drive, van, walk, bicycle; okada, keke e danfo respeitam as suas proibições como em /routes/compute (um elemento de ou para uma zona de proibição é NOT_ALLOWED, com a proibição); motorbike e dispatch apenas as proibições que abrangem todos os motociclos. Pontos a no máximo 400 km de distância de automóvel, 200 km nos outros modos. Motivos: MODE_INVALID, MATRIX_TOO_LARGE, MATRIX_TOO_FAR, WAYPOINT_INVALID, POSTCODE_INVALID, POSTCODE_NOT_FOUND, GHANAPOST_INVALID, GHANAPOST_NOT_FOUND, PLUSCODE_INVALID, ROUTING_UNAVAILABLE (503).
Parâmetros
| Nome | Onde | Tipo | Descrição |
|---|---|---|---|
fields | consulta | string | Lista separada por vírgulas dos campos a manter em cada resultado (a.b entra em objetos; id é sempre mantido; * = todos). |
Corpo do pedido
| Campo | Tipo | Descrição |
|---|---|---|
origins | Waypoint[] | Obrigatório. Pelo menos 1 elementos, no máximo 50 elementos. |
origins[].lat | number | |
origins[].lng | number | |
origins[].postcode | string | |
origins[].ghanaPost | string | |
origins[].plusCode | string | |
origins[].heading | number | Só na origem: sentido de deslocação (graus), para que um veículo em movimento não comece com uma inversão de marcha. |
destinations | Waypoint[] | Obrigatório. Pelo menos 1 elementos, no máximo 50 elementos. |
destinations[].lat | number | |
destinations[].lng | number | |
destinations[].postcode | string | |
destinations[].ghanaPost | string | |
destinations[].plusCode | string | |
destinations[].heading | number | Só na origem: sentido de deslocação (graus), para que um veículo em movimento não comece com uma inversão de marcha. |
mode | string | okada, keke e danfo respeitam as suas proibições (como em /routes/compute); motorbike e dispatch (motas de estafetas) apenas as proibições que abrangem todos os motociclos. Um de: drive, van, okada, motorbike, dispatch, keke, danfo, walk, bicycle. Predefinição: drive. |
allowBans | string[] |
curl -X POST "https://nways.ng/maps/v1/routes/matrix" \
-H "X-NWays-Api-Key: A_SUA_CHAVE_API" \
-H "Content-Type: application/json" \
-d '{"origins":[{"lat":6.4474,"lng":3.472},{"postcode":"LA08A09DB09"}],"destinations":[{"lat":6.43,"lng":3.42},{"lat":6.45,"lng":3.4}],"mode":"motorbike"}'const res = await fetch('https://nways.ng/maps/v1/routes/matrix', {
method: 'POST',
headers: { 'X-NWays-Api-Key': process.env.NWAYS_API_KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({
"origins": [
{
"lat": 6.4474,
"lng": 3.472
},
{
"postcode": "LA08A09DB09"
}
],
"destinations": [
{
"lat": 6.43,
"lng": 3.42
},
{
"lat": 6.45,
"lng": 3.4
}
],
"mode": "motorbike"
}),
})
const data = await res.json()import os
import requests
res = requests.post(
"https://nways.ng/maps/v1/routes/matrix",
headers={"X-NWays-Api-Key": os.environ["NWAYS_API_KEY"]},
json={"origins": [{"lat": 6.4474, "lng": 3.472}, {"postcode": "LA08A09DB09"}], "destinations": [{"lat": 6.43, "lng": 3.42}, {"lat": 6.45, "lng": 3.4}], "mode": "motorbike"},
timeout=10,
)
data = res.json()Resposta
A matriz
| Campo | Tipo | Descrição |
|---|---|---|
elements | object[] | Obrigatório. |
elements[].originIndex | integer | Obrigatório. |
elements[].destinationIndex | integer | Obrigatório. |
elements[].status | string | Obrigatório. NOT_ALLOWED: a origem ou o destino fica dentro de uma zona de proibição para o modo (ban indica qual). Um de: OK, ROUTE_NOT_FOUND, NOT_ALLOWED. |
elements[].durationS | number | Obrigatório. |
elements[].distanceM | number | Obrigatório. |
elements[].ban | Ban | |
elements[].ban.id | string | Obrigatório. |
elements[].ban.zone | string | Obrigatório. |
elements[].ban.scope | string | Obrigatório. |
elements[].ban.hours | string | |
elements[].ban.since | string | |
elements[].ban.source | string (uri) | |
elements[].ban.where | string | Um de: origin, destination, stop, route. |
elements[].ban.walkM | number | |
origins | Point[] | Obrigatório. |
origins[].type | string | Obrigatório. |
origins[].coordinates | number[] | Obrigatório. [lng, lat] Pelo menos 2 elementos, no máximo 2 elementos. |
destinations | Point[] | Obrigatório. |
destinations[].type | string | Obrigatório. |
destinations[].coordinates | number[] | Obrigatório. [lng, lat] Pelo menos 2 elementos, no máximo 2 elementos. |
mode | string | Obrigatório. |
attribution | string | Obrigatório. |
{
"elements": [
{
"originIndex": 0,
"destinationIndex": 0,
"status": "OK",
"durationS": 0,
"distanceM": 0,
"ban": {
"id": "string",
"zone": "Third Mainland Bridge",
"scope": "string",
"hours": "string",
"since": "string",
"source": "string",
"where": "origin",
"walkM": 0
}
}
],
"origins": [
{
"type": "string",
"coordinates": [
0
]
}
],
"destinations": [
{
"type": "string",
"coordinates": [
0
]
}
],
"mode": "string",
"attribution": "string"
}Erros
defaultErro
Que veículo visita que paragens, e por que ordem
POST https://nways.ng/maps/v1/routes/optimize
Modos como em /routes/matrix: as paragens dentro de uma zona de proibição para o modo ficam por atribuir e são listadas em notAllowed. Até 50 paragens e 5 veículos (partida, chegada opcional, capacidade): o menor tempo total dentro da capacidade de cada veículo, por uma heurística rápida sobre os tempos de viagem do motor (não é um ótimo garantido). O percurso de cada veículo é calculado como em /routes/compute, a menos que geometry seja false. Uma chamada route_optimization. Motivos: MODE_INVALID, STOPS_INVALID, VEHICLES_INVALID, STOP_ID_INVALID, VEHICLE_ID_INVALID, STOP_INVALID, CAPACITY_INVALID, STOPS_TOO_FAR, WAYPOINT_INVALID, POSTCODE_INVALID, POSTCODE_NOT_FOUND, GHANAPOST_INVALID, GHANAPOST_NOT_FOUND, PLUSCODE_INVALID, LANG_INVALID, ROUTING_UNAVAILABLE (503).
Corpo do pedido
| Campo | Tipo | Descrição |
|---|---|---|
stops | object[] | Obrigatório. Pelo menos 1 elementos, no máximo 50 elementos. |
stops[].id | string | Obrigatório. |
stops[].location | Waypoint | Obrigatório. Exatamente um de: lat e lng, postcode (NIPOST: encaminha para a sua melhor entrada), ghanaPost ou plusCode (completo, ou curto com uma localidade a seguir). |
stops[].location.lat | number | |
stops[].location.lng | number | |
stops[].location.postcode | string | |
stops[].location.ghanaPost | string | |
stops[].location.plusCode | string | |
stops[].location.heading | number | Só na origem: sentido de deslocação (graus), para que um veículo em movimento não comece com uma inversão de marcha. |
stops[].demand | integer | Predefinição: 1. ≥ 1. |
stops[].serviceS | number | Predefinição: 0. ≥ 0, ≤ 14400. |
vehicles | object[] | Obrigatório. Pelo menos 1 elementos, no máximo 5 elementos. |
vehicles[].id | string | Obrigatório. |
vehicles[].start | Waypoint | Obrigatório. Exatamente um de: lat e lng, postcode (NIPOST: encaminha para a sua melhor entrada), ghanaPost ou plusCode (completo, ou curto com uma localidade a seguir). |
vehicles[].start.lat | number | |
vehicles[].start.lng | number | |
vehicles[].start.postcode | string | |
vehicles[].start.ghanaPost | string | |
vehicles[].start.plusCode | string | |
vehicles[].start.heading | number | Só na origem: sentido de deslocação (graus), para que um veículo em movimento não comece com uma inversão de marcha. |
vehicles[].end | Waypoint | Exatamente um de: lat e lng, postcode (NIPOST: encaminha para a sua melhor entrada), ghanaPost ou plusCode (completo, ou curto com uma localidade a seguir). |
vehicles[].end.lat | number | |
vehicles[].end.lng | number | |
vehicles[].end.postcode | string | |
vehicles[].end.ghanaPost | string | |
vehicles[].end.plusCode | string | |
vehicles[].end.heading | number | Só na origem: sentido de deslocação (graus), para que um veículo em movimento não comece com uma inversão de marcha. |
vehicles[].capacity | integer | 0 = sem limite Predefinição: 0. ≥ 0. |
mode | string | okada, keke e danfo respeitam as suas proibições (como em /routes/compute); motorbike e dispatch (motas de estafetas) apenas as proibições que abrangem todos os motociclos. Um de: drive, van, okada, motorbike, dispatch, keke, danfo, walk, bicycle. Predefinição: drive. |
allowBans | string[] | |
geometry | boolean | Predefinição: true. |
lang | string | Um de: en, fr, pt. |
curl -X POST "https://nways.ng/maps/v1/routes/optimize" \
-H "X-NWays-Api-Key: A_SUA_CHAVE_API" \
-H "Content-Type: application/json" \
-d '{"stops":[{"id":"order-1","location":{"lat":6.44,"lng":3.4},"serviceS":120},{"id":"order-2","location":{"postcode":"LA08A09DB09"},"demand":2}],"vehicles":[{"id":"bike-1","start":{"lat":6.4474,"lng":3.472},"capacity":6}],"mode":"motorbike"}'const res = await fetch('https://nways.ng/maps/v1/routes/optimize', {
method: 'POST',
headers: { 'X-NWays-Api-Key': process.env.NWAYS_API_KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({
"stops": [
{
"id": "order-1",
"location": {
"lat": 6.44,
"lng": 3.4
},
"serviceS": 120
},
{
"id": "order-2",
"location": {
"postcode": "LA08A09DB09"
},
"demand": 2
}
],
"vehicles": [
{
"id": "bike-1",
"start": {
"lat": 6.4474,
"lng": 3.472
},
"capacity": 6
}
],
"mode": "motorbike"
}),
})
const data = await res.json()import os
import requests
res = requests.post(
"https://nways.ng/maps/v1/routes/optimize",
headers={"X-NWays-Api-Key": os.environ["NWAYS_API_KEY"]},
json={"stops": [{"id": "order-1", "location": {"lat": 6.44, "lng": 3.4}, "serviceS": 120}, {"id": "order-2", "location": {"postcode": "LA08A09DB09"}, "demand": 2}], "vehicles": [{"id": "bike-1", "start": {"lat": 6.4474, "lng": 3.472}, "capacity": 6}], "mode": "motorbike"},
timeout=10,
)
data = res.json()Resposta
O plano
| Campo | Tipo | Descrição |
|---|---|---|
routes | object[] | Obrigatório. |
routes[].vehicle | string | Obrigatório. |
routes[].stops | string[] | Obrigatório. Ids das paragens pela ordem de visita |
routes[].durationS | number | Obrigatório. |
routes[].distanceM | number | Obrigatório. |
routes[].serviceS | number | Obrigatório. |
routes[].load | integer | Obrigatório. |
routes[].arrivalsS | number[] | Obrigatório. Segundos desde o início até cada paragem |
routes[].route | Route | |
routes[].route.distanceM | number | Obrigatório. |
routes[].route.durationS | number | Obrigatório. |
routes[].route.staticDurationS | number | Obrigatório. Sem trânsito em direto |
routes[].route.trafficDelayS | number | Obrigatório. O que o trânsito e os incidentes acrescentam agora (traffic_aware). |
routes[].route.speedSource | string | Um de: live, typical, estimated. |
routes[].route.summary | string | |
routes[].route.geometry | LineString | Obrigatório. |
routes[].route.geometry.type | string | Obrigatório. |
routes[].route.geometry.coordinates | number[][] | Obrigatório. |
routes[].route.legs | Leg[] | Obrigatório. Um por troço entre paragens. |
routes[].route.legs[].distanceM | number | Obrigatório. |
routes[].route.legs[].durationS | number | Obrigatório. |
routes[].route.steps | Step[] | Obrigatório. |
routes[].route.steps[].maneuver | string | Obrigatório. depart, arrive, continue, left, right, slight_left, sharp_right, uturn_left, roundabout_enter, ferry_enter, … (outros) |
routes[].route.steps[].instruction | string | Obrigatório. |
routes[].route.steps[].distanceM | number | Obrigatório. |
routes[].route.steps[].durationS | number | Obrigatório. |
routes[].route.steps[].streetNames | string[] | |
routes[].route.steps[].startIndex | integer | Obrigatório. Índice em geometry.coordinates |
routes[].route.steps[].endIndex | integer | Obrigatório. |
routes[].route.steps[].roundaboutExit | integer | |
routes[].route.steps[].toward | string[] | |
routes[].route.steps[].atTrafficLight | boolean | |
routes[].route.steps[].crossing | string | A pé: passagem superior, passagem inferior, passadeira, semáforos, travessia, cruzamento |
routes[].route.segments | object[] | Viagens que mudam a forma de deslocação (comboio, barco, okada com um trajeto a pé para passar uma proibição). |
routes[].route.segments[].mode | string | Obrigatório. Um de: walk, okada, drive, train, boat. |
routes[].route.segments[].line | string | |
routes[].route.segments[].from | string | Obrigatório. |
routes[].route.segments[].to | string | Obrigatório. |
routes[].route.segments[].distanceM | number | Obrigatório. |
routes[].route.segments[].durationS | number | Obrigatório. |
routes[].route.segments[].waitS | number | |
routes[].route.segments[].stops | integer | |
routes[].route.segments[].scheduled | boolean | |
routes[].route.segments[].estimated | boolean | |
routes[].route.segments[].fare | string | |
routes[].route.segments[].note | string | |
routes[].route.segments[].geometry | LineString | Obrigatório. |
routes[].route.congestion | object[] | |
routes[].route.congestion[].startIndex | integer | |
routes[].route.congestion[].endIndex | integer | |
routes[].route.congestion[].level | string | |
routes[].route.tolls | object | |
routes[].route.tolls.gates | object[] | |
routes[].route.tolls.total | object | |
routes[].route.tolls.unknownPrices | integer | |
routes[].route.borderCrossings | object[] | |
routes[].route.borderCrossings[].from | string | |
routes[].route.borderCrossings[].to | string | |
routes[].route.borderCrossings[].location | Point | |
routes[].route.borderCrossings[].atM | integer | |
routes[].route.borderCrossings[].post | string | |
routes[].route.borderCrossings[].clockChangeH | number | |
routes[].route.vehicleRules | object | Viagens de okada, keke e danfo |
routes[].route.vehicleRules.vehicle | string | Um de: okada, motorbike, keke, danfo. |
routes[].route.vehicleRules.avoided | Ban[] | |
routes[].route.vehicleRules.advice | Ban[] | |
routes[].route.vehicleRules.endBan | Ban | |
routes[].route.vehicleRules.allowedByRequest | Ban[] | |
routes[].route.vehicleRules.reported | object[] | |
routes[].route.lastMile | object | |
routes[].route.lastMile.stopAt | Point | |
routes[].route.lastMile.stopName | string | |
routes[].route.lastMile.mode | string | |
routes[].route.lastMile.distanceM | number | |
routes[].route.lastMile.durationS | number | |
routes[].route.lastMile.geometry | LineString | |
routes[].route.access | object | |
routes[].route.access.kind | string | Um de: estate, government, military, police, gate. |
routes[].route.access.text | string | |
routes[].route.access.name | string | |
routes[].route.access.gate | Point | |
routes[].route.access.dropOffAtGate | boolean | |
routes[].route.roadCondition | object | |
routes[].route.roadCondition.roughM | number | |
routes[].route.country | string | |
routes[].route.warnings | string[] | |
routes[].route.fares | FareEstimate[] | |
routes[].route.fares[].mode | string | Obrigatório. Um de: taxi, shared_taxi, okada, keke, bus, ridehail, boat. |
routes[].route.fares[].service | string | |
routes[].route.fares[].currency | string | Obrigatório. Um de: NGN, GHS, XOF. |
routes[].route.fares[].low | integer | Obrigatório. |
routes[].route.fares[].typical | integer | Obrigatório. |
routes[].route.fares[].high | integer | Obrigatório. |
routes[].route.fares[].text | string | Obrigatório. |
routes[].route.fares[].perPerson | boolean | Obrigatório. |
routes[].route.fares[].charter | boolean | Obrigatório. |
routes[].route.fares[].night | boolean | |
routes[].route.fares[].rush | boolean | |
routes[].route.fares[].rain | boolean | |
routes[].route.fares[].basis | string | Obrigatório. Um de: crowd, guide. |
routes[].route.fares[].reports | integer | Obrigatório. |
routes[].route.fares[].durationS | number | Obrigatório. |
routes[].route.fares[].openingOffer | integer | Onde os preços se regateiam: uma boa primeira oferta. |
routes[].route.fares[].sources | string (uri)[] | |
unassigned | string[] | Obrigatório. |
notAllowed | object[] | Paragens, ou partidas e chegadas de veículos, dentro de uma zona de proibição para o modo. |
notAllowed[].stop | string | |
notAllowed[].vehicle | string | |
notAllowed[].ban | Ban | Obrigatório. |
notAllowed[].ban.id | string | Obrigatório. |
notAllowed[].ban.zone | string | Obrigatório. |
notAllowed[].ban.scope | string | Obrigatório. |
notAllowed[].ban.hours | string | |
notAllowed[].ban.since | string | |
notAllowed[].ban.source | string (uri) | |
notAllowed[].ban.where | string | Um de: origin, destination, stop, route. |
notAllowed[].ban.walkM | number | |
durationS | number | Obrigatório. |
mode | string | Obrigatório. |
attribution | string | Obrigatório. |
{
"routes": [
{
"vehicle": "string",
"stops": [
"string"
],
"durationS": 0,
"distanceM": 0,
"serviceS": 0,
"load": 0,
"arrivalsS": [
0
],
"route": {
"distanceM": 0,
"durationS": 0,
"staticDurationS": 0,
"trafficDelayS": 0,
"speedSource": "live",
"summary": "Admiralty Way and Awudu Ekpekha Boulevard",
"geometry": {
"type": "string",
"coordinates": []
},
"legs": [
{}
],
"steps": [
{}
],
"segments": [
{}
],
"congestion": [
{}
],
"tolls": {
"gates": [],
"total": {
"NGN": 300
},
"unknownPrices": 0
},
"borderCrossings": [
{}
],
"vehicleRules": {
"vehicle": "okada",
"avoided": [],
"advice": [],
"endBan": {},
"allowedByRequest": [],
"reported": []
},
"lastMile": {
"stopAt": {},
"stopName": "string",
"mode": "string",
"distanceM": 0,
"durationS": 0,
"geometry": {}
},
"access": {
"kind": "estate",
"text": "string",
"name": "string",
"gate": {},
"dropOffAtGate": true
},
"roadCondition": {
"roughM": 0
},
"country": "string",
"warnings": [
"string"
],
"fares": [
{}
]
}
}
],
"unassigned": [
"string"
],
"notAllowed": [
{
"stop": "string",
"vehicle": "string",
"ban": {
"id": "string",
"zone": "Third Mainland Bridge",
"scope": "string",
"hours": "string",
"since": "string",
"source": "string",
"where": "origin",
"walkM": 0
}
}
],
"durationS": 0,
"mode": "string",
"attribution": "string"
}Erros
defaultErro