Get Fastest Routes

Products Used: Directions API & Navigation API

NextBillion.ai’s routing APIs offer the feature to select the type of route, namely fastest and shortest, to be suggested by the services. We can use the “route_type” attribute available in Directions and Navigation Flexible APIs to get the fastest possible route between 2 locations along with other details about the route.

Following is a Directions flexible request to get the shortest route with following configurations:

  1. An “origin” and “destination” for the trip
  2. “mode” option set to “car”
  3. “option” attribute set to “flexible”
  4. “route_type” option set to “fastest”

Directions API request

1
curl --location 'https://api.nextbillion.io/directions/json?origin=39.35555925,-76.61005664&destination=39.31131584,-76.61936891&mode=car&key=<your_api_key>&option=flexible&route_type=fastest'

Directions API response

1
{
2
"status": "Ok",
3
"routes": "[...]"
4
}

Notice that if the “route_type” is changed to “fastest” then, although the trip duration is lesser than what is suggested in case of “shortest” route type setting, the distance is greater as compared to this case.

Let’s take a look at how a Navigation API call would look like for the exact same parameters as the above example.

1
curl --location 'https://api.nextbillion.io/navigation/json?origin=39.35555925,-76.61005664&destination=39.31131584,-76.61936891&mode=car&key=<your_api_key>&option=flexible&route_type=fastest'
1
{
2
"status": "Ok",
3
"routes": "[...]"
4
}

Visit Directions API | Navigation API documentation to know more about the available features.

© 2024 NextBillion.ai all rights reserved.