Transition Polylines and Route Tokens

This scenario generates route tokens with route polylines using the Route Optimization API.

In your OptimizeToursRequest message, set populateTransitionPolylines (REST, gRPC) to generate routePolyline (REST, gRPC) and routeToken (REST, gRPC) fields in the transitions for a ShipmentRoute in the OptimizeToursResponse.

See an example request with populateTransitionPolylines=true

{
  "populateTransitionPolylines": true,
  "model": {
    "shipments": [
      {
        "pickups": [
          {
            "arrivalLocation": {
              "latitude": 37.73881799999999,
              "longitude": -122.4161
            }
          }
        ],
        "deliveries": [
          {
            "arrivalLocation": {
              "latitude": 37.79581,
              "longitude": -122.4218856
            }
          }
        ]
      }
    ],
    "vehicles": [
      {
        "startLocation": {
          "latitude": 37.73881799999999,
          "longitude": -122.4161
        },
        "endLocation": {
          "latitude": 37.73881799999999,
          "longitude": -122.4161
        },
        "costPerKilometer": 1.0
      }
    ],
    "globalStartTime": "2024-02-13T00:00:00.000Z",
    "globalEndTime": "2024-02-14T06:00:00.000Z"
  }
}
    

See an example response to the request with populateTransitionPolylines=true

{
  "routes": [
    {
      "vehicleStartTime": "2024-02-13T00:00:00Z",
      "vehicleEndTime": "2024-02-13T00:39:02Z",
      "visits": [
        {
          "isPickup": true,
          "startTime": "2024-02-13T00:00:00Z",
          "detour": "0s"
        },
        {
          "startTime": "2024-02-13T00:19:43Z",
          "detour": "0s"
        }
      ],
      "transitions": [
        {
          "travelDuration": "0s",
          "waitDuration": "0s",
          "totalDuration": "0s",
          "startTime": "2024-02-13T00:00:00Z",
          "routePolyline": {}
        },
        {
          "travelDuration": "1183s",
          "travelDistanceMeters": 8591,
          "waitDuration": "0s",
          "totalDuration": "1183s",
          "startTime": "2024-02-13T00:00:00Z",
          "routePolyline": {
            "points": "}{ieFlkdjV?A@I?E@K?S@K?GB]@W?C?G@O?C@E?E@EB_AB_@?G?Q?KAQCm@?MAOAU?K?A?C?CAK?K?A?A?A?CAC?QAM?KASAE?C?CAEAC?ACGIO]s@ACAACCAECEAEEECIKSOYEIMWCGIMGKCIGMAAEI?ACGAC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Hs@H]HC?_@F_@DYDc@D_@Dy@Ja@D}APYDI@E?QBO@uAPWDYBMBQ@E@C?YD}@L]Da@Fy@Hs@Fk@Hs@Fi@Fa@F_@DYB[Hw@HI@_AJ[DWDMBi@FO@w@JWDK@e@FM@g@Di@FSB]F_@F}@J[Da@D_@DUBeALG@UBe@F]F_@DiANoANu@F_@Di@Fq@JK@QB[D_ALs@JUBaAJy@J]D[@c@DgALg@F[Hw@Hq@HU@[DSsCMqBCWDSRC"
          },
          "routeToken": "CvMBCpoBMpcBGnwKJwIWCTqXLDcqhgCkvimDkSzlkpMC-vjWAaDKOd3tCNPWjgKY9ZoCABIkp-WKdQga3q4YIIiUZ4H3B1KNfwDrYPeL9O2eVJwjIWAzanUeGgsAIAW-AdIBAg8hCioJIAJwdXUNbR4bPWHfPD9FaRDGPkjIybzk-fDMxbIBIhdUUlBpWnQ2NkJNeTRrZVFQdy02ZjhRVRAFGjsKOQoYCg0KAggBEQAAAAAAgGZAEQrXo3A9YZRAEgAiGQoXVFJQaVpzV1ZCTXk0a2VRUHctNmY4UVUoASIVANvZE2tQPAWkpIsvQ700Jn8qVo_m"
        },
        {
          "travelDuration": "1159s",
          "travelDistanceMeters": 8765,
          "waitDuration": "0s",
          "totalDuration": "1159s",
          "startTime": "2024-02-13T00:19:43Z",
          "routePolyline": {
            "points": "{~teF`oejVHARCjAOr@IFx@NzBHtA?HBXBl@ZI^ENAl@It@IRC`AM~@KZEZE`@Gf@G`@GHAZEj@EZAfBUTCfC]ZE\\Gj@Gl@Gp@IREZE`AMRCf@E`@GVEXCj@G\\Ez@K\\Gf@ELCHA`@G\\C\\GRA|@MfAM`@Ep@Ih@G|@K\\ERCTCr@I~@K\\GXEPAp@I|@K\\EXE~@QbAKDATAzDe@VEd@ELALAVEVCNCHAVCRCLC^EVEPAZGj@Gn@I~ASj@I^E~BW^ENAtASn@GZE^E`AKd@I\\GXE\\Eb@Gr@Kd@IPEXGbB_@l@MXGb@I`AUp@O@AbAUREHC`@ED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Ad@Ct@A\\Aj@Cp@Ab@Aj@Aj@Cb@?\\ANAj@AN?F?BA`@?B@D?@?B@BBF?@DH@@FLBHFJHLBFLVDHNXJRBHDD@DBD@DBB@@@B\\r@HNBF?@@B@D?B?B@D@R?J@L?P@B?B?@?@?@?J@J?B?B?@?J@T@N?LBl@@P?J?P?FC^C~@AD?DAD?BAN?F?BAVC\\?FAJ?RAJ?DAH?@"
          },
          "routeToken": "CvsBCqIBMp8BGoMBCisCFgtG1Hlkf4MAwCL3qQKkpALomZ4Ci7meAozjjAPP34kDmSPq3BeDoWEAEiQzanUe6iFiW5kIYp6_RksOUl0YSWqIhERXJcl7xeckmqblinUaCgALCSuQBwIAdR4qCTkbWSARAAocAzICAgE9aRDGPkU-QYY-SIWx4e-az6a28QEiF1RSUGladU8zQk15cmtlUVBvZnVyd0FzEAUaOwo5ChgKDQoCCAERAAAAAACAZkARCtejcD0ulEASACIZChdUUlBpWnQtVkJNeXJrZVFQb2Z1cndBcygBIhUA29kTa1qXXaY59KJpCuXOkxw-Vkw"
        }
      ],
      "metrics": {
        "performedShipmentCount": 1,
        "travelDuration": "2342s",
        "waitDuration": "0s",
        "delayDuration": "0s",
        "breakDuration": "0s",
        "visitDuration": "0s",
        "totalDuration": "2342s",
        "travelDistanceMeters": 17356
      },
      "routeCosts": {
        "model.vehicles.cost_per_kilometer": 17.356
      },
      "routeTotalCost": 17.356
    }
  ],
  "metrics": {
    "aggregatedRouteMetrics": {
      "performedShipmentCount": 1,
      "travelDuration": "2342s",
      "waitDuration": "0s",
      "delayDuration": "0s",
      "breakDuration": "0s",
      "visitDuration": "0s",
      "totalDuration": "2342s",
      "travelDistanceMeters": 17356
    },
    "usedVehicleCount": 1,
    "earliestVehicleStartTime": "2024-02-13T00:00:00Z",
    "latestVehicleEndTime": "2024-02-13T00:39:02Z",
    "totalCost": 17.356,
    "costs": {
      "model.vehicles.cost_per_kilometer": 17.356
    }
  }
}
    

Start a navigation session in Navigation SDK with a route token from the OptimizeTourResponse. The navigation session attempts to follow the route returned by the Route Optimization API. Due to dynamic road conditions, a route generated with a given token may differ from the original route. Although route tokens don't expire, we recommend using the route token as soon as feasible after token generation to maximize how close the actual route is to the planned route.

When passing a route token generated by Route Optimization API to the Navigation SDK using Navigator.setDestinations method, you must specify a single destination that matches the end location of the ShipmentRoute transition.

For more information on route tokens, see the Plan a route documentation for Navigation SDK for Android and Navigation SDK for iOS.

For details about route polyline encoding, see Polylines.