Snap To Roads API

Introduction

NextBillion.ai’s Snap To Roads API takes a series of locations and snaps them to nearby roads representing the best-matched route where a trip took place connecting all the given locations. Users can choose to retrieve a geometry of the route connecting all the points while using several other configurations. They can also choose to receive the segment-wise speed limits of the route identified in the response.

GET

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

GET Request

Users can build a basic GET request using the 2 required parameters, key and path, to obtain accurate road-snap data. They can further customize the request by including other optional parameters as listed in the table below.

It is recommended to use the GET method when the number of coordinate points in the path parameter is less than 100.

Request Parameters

Loading..

POST Request

Snap To Road API supports HTTPS POST method as well. The parameters and their properties for the POST method are the same as listed in the Request Parameters section. The key is passed as a query parameter whereas other parameters need to be part of the Request Body. An example of a POST request is added in the Sample Queries section below.

Please note that the maximum number of path coordinate points allowed in a POST request is 200.

Response Schema

Loading..

Sample Queries

GET Request Example 1

Let’s create a simple snapToRoad request with:

  • 4 path coordinate points that need to be snapped to the nearest road

  • radiuses values configured for each of the path coordinate points

  • timestamps added for each of the path coordinate points

Request

1
curl --location 'https://api.nextbillion.io/snapToRoads/json?key=<your_api_key>&path=34.02632257,-118.31353281|34.05029825,-118.29896811|34.04873267,-118.24571761|34.02951637,-118.23833125&radiuses=20|25|15|30&timestamps=1681834632|1681835232|1681835832|1681836632'

Response

1
{
2
"status": "Ok",
3
"snappedPoints": "[...]"
4
"distance": "...",
5
"geometry": "..."
6
}

Here is a visual representation of the above response

Snap To Roads API example

GET Request Example 2

Let’s take a step further and expand the request from Example 1 to add:

  • geometry=geojson to get the geoJSON details of the snapped path

  • get a snapped route that a truck can take

Request

1
curl --location 'https://api.nextbillion.io/snapToRoads/json?key=<your_api_key>&path=34.02632257,-118.31353281|34.05029825,-118.29896811|34.04873267,-118.24571761|34.02951637,-118.23833125&radiuses=20|25|15|30&timestamps=1681834632|1681835232|1681835832|1681836632&mode=truck&geometry=geojson'

Response

1
{
2
"status": "Ok",
3
"snappedPoints": "[...]"
4
"distance": "...",
5
"geometry": "..."
6
}

Below is a visual representation of the above response. Notice the slight differences in the route that is appropriate for a truck instead of a car from Example 1.

Snap To Roads API example 2

POST Request Example

Now, let’s see how the POST request for the same scenario from Example 2 above looks like

1
curl --location --request POST 'https://api.nextbillion.io/snapToRoads/json?key=<your_api_key>'
2
--header 'Content-Type: application/json'
3
--data-raw '{
4
"path":"34.02632257,-118.31353281|33.99120320,-118.29522906|34.00024016,-118.26026685|33.99205579,-118.20885182",
5
"radiuses":"20|25|15|30",
6
"timestamps":"1681834632|1681835232|1681835832|1681836632",
7
"mode":"truck",
8
"geometry":"geojson"
9
}'

API Query Limits

  • The maximum number of coordinate points that can be added to the path parameter in a GET request is 100 and in a POST request is 200.

  • 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
200

Normal success case.

Normal success case.

400

Input validation failed.

There is a missing or invalid parameter or a parameter with an invalid value type is added to the request.

401

APIKEY not supplied or invalid.

This error occurs when the wrong API key is passed in the request or the key is missing altogether

403

APIKEY 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.

404

Requested host/path not found.

This error occurs when a malformed hostname is used

413

Request entity too large

This 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] if the issue still persists.

422

Could not process the request.

The points could not be snapped successfully for the given combination of location coordinates or the parameters.

429

Too many requests.

QPM or API request count quota reached

500

Internal Service error.

There was an internal issue with NextBillion.ai services. You can reach out to [email protected] for an explanation.

© 2024 NextBillion.ai all rights reserved.