Asynchronous Distance Matrix API
NextBillion.ai’s Asynchronous Distance Matrix API computes distances and ETAs between a large set of origins and destinations — could be for one-to-many or many-to-many scenarios. The API call returns the ETAs and distances for each origin and destination pair.
For example, if a set has Origins {A,B} and Destinations {C,D,E} we can get the following matrix of results with distance (meters) and time (seconds) for each.
As the name suggests, Asynchronous Distance Matrix API returns the result asynchronously. In the first step, users submit an HTTPS POST request containing the origin and destination coordinates. On successfully submitting the request the service would return a unique task ID. In the next step, the users can use this task ID to retrieve the result via an HTTPS GET request.
The Asynchronous Distance Matrix API has 2 versions - Fast and Flexible. We will be talking about both these services below.
Asynchronous Distance Matrix Fast
The Fast version of Asynchronous Distance Matrix returns the ETAs and distances between all combinations of provided origin and destination pairs for the given driving mode. To utilize the service users can make a POST request with the required fields of key
and origins
. Additionally, users can customize their request by including other optional parameters as listed in the table below.
Request Parameters
Loading..POST Request Body
Loading..Response Schema
Loading..Asynchronous Distance Matrix Flexible
The Flexible version of Asynchronous Distance Matrix allows users to make use of a few additional parameters like - truck specific constraints, add a departure time for the service to utilize the typical traffic conditions at the time, and add a preference for the fastest
or the shortest
route type. Users can send a HTTP POST request containing the mandatory parameters of key
, origins
and option
along with other optional attributes to create a distance matrix task.
It is worth highlighting that to use the flexible version of the API users need to set the option
parameter to flexible
. Also, the Flexible-only attributes are not available in the Fast version and will be ineffective, if used.
Request Parameters
Loading..POST Request Body
Loading..Response Schema
Loading..Sample POST Request
Let’s take a look at an example POST request, where we:
- Add just one pair of
origin
anddestination
for simplicity. - Set
mode=truck
to get the ETA and distance of a route pliable by a truck - Define the dimensions and weight of the truck.
- Add
option=flexible
to ensure that truck parameters are effective
Sample POST Response
Here is the response that we receive on submitting the POST request. The ID received in the response will be used in subsequent sample examples for HTTPS GET method.
Asynchronous Distance Matrix GET Method
Use this method to retrieve the Distance Matrix solution link for the tasks created using either of the Asynchronous Distance Matrix POST methods.
Request Parameters
Loading..Response Schema
Loading..Sample GET Request
Let’s retrieve the result for the request submitted in the POST request example. We add the API Key and the id received from the response of the POST method.
Sample GET Response
Once the service is done with processing the request, following response is returned:
Read the Distance Matrix Results
Users can then copy the result link from the GET response and open it in a browser. The CSV file that the browser accesses contains the result of Asynchronous Distance Matrix request and the information is arranged as per the following column nomenclature and order
Following is a sample result for reference:
API Query Limits
- For both Asynchronous Distance Matrix Fast & Flexible methods, NextBillion.ai allows a default limit of up to 4000 x 4000 Origin and Destination set
- 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 10 queries per second for the POST method and 50 queries per second for the GET method for continuous requests. Note: We can increase the quota if needed, on request. Contact [email protected] for more details.