Get shortest 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 shortest 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 “shortest”

Directions API request

1curl --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=shortest'

Directions API response

1{
2 "status": "Ok",
3 "routes": [
4 {
5 "geometry": "ureoFz{qrM?E@Yh@A^?T?RAp@Ar@?HA|@CH?h@?nACZ?vACT?dAAbACH?ZAd@AR?n@AnAAR?`@A~AC`A?VAbA?v@AH?r@AtBAh@AJ?Z?~AAHA`@?Z?z@Ah@Ad@?x@A`@AX?P?lBAjBAJ?H?n@?xB@h@?l@?jB?rB?lA?J?vA@ZAj@AbACX?p@CZ?p@?Z?tA?|@AnA?P?h@AhA?R?b@?R?lAArA?BrBHvBNbE?N@`@@j@Ab@?R?^A^Ch@K|AIjAC^A^A^AtA?V?L?Hh@Gn@Ef@Ab@?`@B`@Dd@Jp@T\\NLFLHTLZPp@b@v@f@VLp@Xf@Nz@Rv@J^DnAFv@@\\AH?DAJ?XAF?`@C^Av@CZAXAr@?~@?|@E\\Ab@A`@Ah@?l@AhAE@f@DpBBxB?\\@Z?FTAN?|BI~AGp@AfAA@V@L@HFJzAvBNRbCjDd@p@NPH@NLLJTHRBPBJ?R@Z?R@H?LAlAELAV?`@C`@AzBGbACzDQf@AXAv@AZ?|@CbAC^C`@A\\Cn@AnAEXAJ?`@C@?j@CrBED?xCIXAtAEp@AnAEhBENAXAh@AN?p@CrCGf@A^AL?dAEl@CJ?^Af@EF?HAZ?\\?",
6 "distance": 5663.966,
7 "duration": 1065.549,
8 "start_location": {
9 "latitude": 39.35546,
10 "longitude": -76.61006
11 },
12 "end_location": {
13 "latitude": 39.31132,
14 "longitude": -76.61931
15 },
16 "legs": [
17 {
18 "distance": {

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.

1curl --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=shortest'
1{
2 "status": "Ok",
3 "routes": [
4 {
5 "geometry": "ycaajAx_|bqC@u@NqGhLItHE`FCzDCtNUdOOdBClRg@lBC`LKvWY|GIrZ[`FIjTYnT[hBCjGQvJKjEEzMO|WYnEGrIKf]a@vSOfFE`TOpPMfBChOIxc@S|KQ~B@vGGv\\[fBApIGvGGxQOfLKrJEfQSpIKfGGtDEha@Ov`@GlBEpBC|M?~d@RlL?|L?t`@Bnc@BnW@jB?~ZBjGMrLShT_@fGInN[vGGzNAjGFbZKhRG~WIvDAfLEfVGtDClJC~D?xWC~XAf@`c@bBdd@dDf|@DhDLvILpLKjJE`EGlIOtH]fL{Bd\\kBxVe@dISvHGjI]tY?jFBhC?dBfLeA`NaApKQfJBlI^pI`A`KhBtNbF~G~CnCrAlC|ArEjCtGtDbObJ~OpKrFdCxNnGbKvCjRfE`PxBfI`A`XlAdPRnHShBIr@CzBEvFYvAGlIWfIYtPc@hGQhGSdOE~RCdRu@vHQhJUtIMtKOxMS`Vm@PpKp@jb@h@he@HhHHvG@pA~EO`DKbf@_B|\\iA~NSnU[RpFJ~B\\nB`ArBf\\xd@lCvDxh@~t@|JjNnCbEjBFzCnCtCrBzE~A|Dj@vD`@vBNzDTdH?`EBfBBbCGlWeAnCOrF@jIq@tISze@kAdTi@xy@iDjK]hGMjPUvGIhRe@dTg@hIa@fIUtH]~M[dXy@pFQ`CIrI[VArLa@zb@cAlACzn@eBjGQzYu@jN_@|Wq@~_@_AfDIxFOpLYtCI`Oe@dm@eAjKYvHMhCMbUi@`Mk@vBGdIWhK{@vAC|ACtGCxHE",
6 "distance": 5663.966,
7 "duration": 1065.549,
8 "start_location": {
9 "latitude": 39.355469,
10 "longitude": -76.610061
11 },
12 "end_location": {
13 "latitude": 39.311317,
14 "longitude": -76.619308
15 },
16 "legs": [
17 {
18 "distance": {

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

Have Questions ?