Get Shortest Route

Implement Using: Directions Flexible API

When the business requirements are such that a shortest route between 2 places is most desirable, users can make use of the route_type parameter of Directions Flexible API to generate a route with least traveling distance. To configure the request for this example we add:

  • origin & destination to to denote the starting and end locations of the trip
  • mode set to “car” to get a route which a car can take
  • route_type parameter set to “shortest”
  • option set to “flexible”

Request

1curl --location 'https://api.nextbillion.io/directions/json?origin=34.03113938,-118.20745576&destination=34.02842053,-118.26701916&mode=car&key=<your_api_key>&route_type=shortest&option=flexible' \
2--header 'Content-Type: application/json'

Response

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

Following is a visual representation of the above route on a map. We can observe that the highway route which could have been faster but lengthier, is avoided because of the “route_type” setting.

docs-image