Directions API

Introduction

Nextbillion.ai’s Directions API is a service that computes a route between two places. With the Directions API, you can:

  • Find the most optimal route and ETAs between the origin and the destination.
  • Get directions for different driving modes like car & truck.
  • You can also add waypoints, which are coordinates along the route.
  • Plan your trips in advance by setting departure_time to get best routes and ETAs
  • Get different routes based on different truck dimensions and weight.

The Directions API has 2 versions to cater to different business needs. First, is the Fast version which would return the route and related information in real time. Second, is the Flexible version which offers truck routing and time-based routing features in addition to those available in the Fast version. We will be talking about both these services below

Also check out NextBillion's Road Editor API for easy manipulation and custom updates to road network data, enhancing the utility of Directions API response in meeting your business needs

Directions Fast API

GET

https://api.nextbillion.io/directions/json?key={your_api_key}


The Directions Fast API gets the directions in real time for trips starting at current time. The routes returned through this service have the traffic conditions factored in to avoid any delays under usual circumstances.

Directions Fast API service can take input using both HTTPS GET and POST requests. Request URL, parameters and response schema are exactly the same for both methods. However, an important difference between these two input methods is in the maximum number of waypoints that can be added to the input. We will cover them below.

GET Request

To utilize the Directions API and obtain route information, a GET request is made with the required parameters: key, origin, and destination. To customize the request, additional parameters such as waypoints, mode and avoid can be included based on the user's preferences.

Please note that the maximum number of waypoints allowed in a GET request is 50.

Request Parameters

Loading..

POST Request

The parameters and their properties for the Directions Fast POST version are the same as listed in the Request Parameter section. The key is passed as a request parameter and the rest of the parameters should be included in the Request Body. An example of a POST request is added in the Sample Queries-Directions Fast section below.

Please note that the maximum number of waypoints allowed in a POST request is 200.

Response Schema

Loading..

Sample Queries-Directions Fast

GET Request Example 1

Let’s look at a simple directions request with

  • an origin and destination pair for a trip being made by a car
  • a request for a simplified route geometry in the response
  • steps set to true to get turn-by-turn information for the complete route

Request

1 curl --location 'https://api.nextbillion.io/directions/json?origin=34.04367949,-118.30921138&destination=34.06660028,-118.24728963&mode=car&key=<your_api_key>&overview=simplified&steps=true'

Response

1{
2 "result":"Ok",
3 "routes":"{...}"
4}

Here is a visual representation of the above response

direction example 1

GET Request Example 2

Taking the next step to use further features offered in Directions API. For the same origin and destination, let’s request:

  • full route geometry instead of simplified
  • a waypoints to be added in the request along with approaches information
  • to avoid highways in the returned route
  • to remove steps information from the response

Request

1curl --location 'https://api.nextbillion.io/directions/json?origin=34.04367949,-118.30921138&destination=34.06660028,-118.24728963&mode=car&key=<your_api_key>&overview=full&avoid=highway&waypoints=34.05558063,-118.27052810&appraoches=unrestricted;curb'

Response

1{
2 "result":"Ok",
3 "routes":"{...}"
4}

And here is a visual representation of the above response. We can see a different route is suggested when a waypoint is added and the API is requested to avoid highway.

direction example 1

POST request Example

Let’s look at a Directions Fast POST method request with values for different parameters to configure a request

1curl --location --request POST ‘https://api.nextbillion.io/directions/json?key=<your_api_key>
2--header 'Content-Type: application/json'
3--data '{...}'

Directions Flexible API

GET

https://api.nextbillion.io/directions/json?option=flexible&key={your_api_key}


The Directions Flexible API offers customizable features for determining routes accurately. It can serve requests for truck specific routing, time based routing, choosing between fastest and shortest route types and also offers to return segment-wise speed limits of the route suggested. The traffic conditions are also factored in, to avoid delays under usual circumstances.

To use the Directions Flexible API service please set the option parameter to flexible. Please note some request and response parameters available in the Fast version are not available in Flexible version and vice-versa.

The Flexible version also supports both HTTPS GET and POST methods. Request URL, parameters and response schemas are exactly the same for both methods. However, an important difference between these two input methods is in the maximum number of waypoints that can be added to the input. We will cover them below.

GET Request

To utilize the Directions Flexible API and obtain route information, a GET request is made with the required parameters: key, origin, destination and option. To customize the request, additional parameters such as waypoints, mode and avoid can be included based on the user's preferences.

Please note that the maximum number of waypoints allowed in a GET request is 50.

Request Parameters

Loading..

POST Request

The parameters and their properties for the Directions Flexible POST version are the same as listed in the Request Parameter section. The key and option are passed as query parameters and the rest of the parameters should be included in the Request Body. An example for a POST request is added in the Sample Queries - Directions Flexible section below.

Response Schema

Loading..

Sample Queries-Directions Flexible

GET Request Example 1

Using the same origin and destination pair from the example from Directions Fast, let's see how different routes are suggested by Directions Flexible for different configurations of parameters. Let’s start by creating a simple flexible request for

  • a trip being made by a truck
  • a specific departure_time

Request

1curl --location 'https://api.nextbillion.io/directions/json?origin=34.14169142%2C-118.11283644&destination=34.00419854%2C-118.08278668&mode=truck&departure_time=1683105152&option=flexible&key=<your_api_key>'

Response

1{
2 "result":"Ok",
3 "routes":"{...}"
4}

Here is a visual representation of the above response

Direction Example 3

GET Request Example 2

In the next next step let’s request the route between same origin and destination but for

  • different departure_time
  • different truck parameters
  • shortest route type
  • avoiding highway

Request

1https://api.nextbillion.io/directions/json?origin=34.14169142,-118.11283644&destination=34.00419854,-118.08278668&mode=truck&avoid=highway&departure_time=1683220363&option=flexible&route_type=shortest&truck_size=220,200,400&key=<your_api_key>

Response

1{
2 "result":"Ok",
3 "routes":"{...}"
4}

Following is a visual representation of the above response. Observe that choosing the shortest path and adding other configurations, changes the suggested route.

Direction Example 4

GET Request Example 3

In this example, let’s check how to avoid routes with axle load restrictions

  • an origin and destination pair for a trip being made by a truck
  • Set truck_axle_load to allow routing trucks not exceeding a load of 9 tonnes per axle

Request

1curl --location 'https://api.nextbillion.io/directions/json?origin=32.66167876,-97.33248769&destination=32.66161249,-97.35607262&mode=truck&key=<your_api_key>&option=flexible&truck_axle_load=9'

Response

1{
2 "result":"Ok",
3 "routes":"{...}"
4}

Observe that setting the axle load parameter to 0 tonnes returns a route through a narrow street which evidently is not fit to be used by a truck with a large load.

GET Request Example 4

In this example we will create a request for avoiding a U turn which can be a tricky maneuver for a truck to perform.

  • an origin and destination pair for a trip being made by a truck
  • avoid parameter set to uturn

Request

1curl --location 'https://api.nextbillion.io/directions/json?origin=38.85739691,-77.05348619&destination=38.85740647,-77.05261010&avoid=uturn&mode=truck&key=<your_api_key>&option=flexible'

Response

1{
2 "result":"Ok",
3 "routes":"{...}"
4}

Observe that removing the “uturn” constraint gives a relatively shorter route but with a major U-turn maneuver.

POST request Example

Let’s look at a Directions Flexible POST method request with values for different parameters to configure a request

1curl --location --request POST ‘https://api.nextbillion.io/directions/json?key=<your_api_key>&option=flexible’
2--header 'Content-Type: application/json'
3--data '{...}'

API Query Limits

  • Following are the maximum number of waypoints allowed in a single request:
    • Directions Fast
      • 50 when using HTTPS GET
      • 200 when using HTTPS POST
    • Directions Flexible have a limit of 50 waypoints when irrespective of the HTTPS method used.
  • Maximum dimensions allowed for truck_size are 5000 cm for length, 5000 cm for width, 1000 cm for height.
  • Maximum weight allowed for truck_weight (including the trailer and shipped goods) is 100,000 kg
  • NextBillion.ai allows a maximum rate limit of 6000 queries per minute or 100 queries/second for continuous requests.
    Note: We can increase the quota if needed, on request. Contact [email protected] for more details.

API Error Codes

Response CodeDescriptionAdditional Notes
200Normal success case.Normal success case.
400Input validation failed.There is a missing or an invalid parameter or a parameter with an invalid value type is added to the request.
401APIKEY not supplied or invalid.This error occurs when the wrong API key is passed in the request or the key is missing altogether
403APIKEY is valid but does not have access to requested resources.You might be querying for a geographical region which is not valid for your account, or requesting a service which is not enabled for you.
404Requested host/path not found.This error occurs when a malformed hostname is used.
413Request entity too largeThis error is caused when the length of input request URI or the request body is too large. Please modify the request. Reach out to [[email protected]](mailto:[email protected]) if the issue still persists.
422Could not process the request.Valid route could not be generated for the given parameters
429Too many requests.QPM or API request count quota reached
500Internal Service error.There was an internal issue with NextBillion.ai services. You can reach out to [[email protected]](mailto:[email protected]) for an explanation.