By default, intermediate waypoints are used for stopping for pickups and dropoffs, but you can also specify that an intermediate waypoint is meant just to pass through.
A route that contains an origin waypoint, a pass-through intermediate
waypoint, and a destination waypoint contains just one route leg that
connects the origin and the destination, while passing through the intermediate
(called a via
) waypoint.
Configure an intermediate waypoint to be a pass-through waypoint by
setting the via
property of the waypoint to true
using the
Waypoint interface.
The via
property is most effective when creating routes in response to
the user dragging the waypoints on the map. Doing so allows the user to see how
the final route may look in real-time and helps ensure that waypoints are placed
in locations that are accessible to the Routes library.
Example request
The following example request demonstrates how to mark an intermediate waypoint as a pass-through waypoint.
const routeRequestWithVia = { origin: '100 Moffett Blvd, Mountain View, CA 94043', destination: '1199 9th Ave, San Francisco, CA 94122', travelMode: 'DRIVING', intermediates: [ {location: 'Half Moon Bay, CA', via: true} // Set the via property to true ], fields: ['path', 'legs'], }; // Make the request. const {routes, fallbackInfo, geocodingResults} = await Route.computeRoutes(routeRequestWithIntermediates);
Access place IDs for intermediate waypoints
If you specify the location of an origin, destination, or intermediate waypoint as an
address string or as a Plus code, the Routes library
attempts to find the most relevant location which has a corresponding place ID. The geocodingResults.intermediates
array in the results contains the place ID corresponding to the location of the waypoints, along
with additional data about the location.
Example geocoding results response
{ "origin": { "geocoderStatus": "OK", "types": [ "premise", "street_address" ], "partialMatch": false, "placeId": "ChIJb5NgcTa3j4ARrfF4Oc_f6q8", "intermediateWaypointRequestIndex": null }, "destination": { "geocoderStatus": "OK", "types": [ "premise", "street_address" ], "partialMatch": false, "placeId": "ChIJAbIPLl2HhYARQ0SSdDFxU-s", "intermediateWaypointRequestIndex": null }, "intermediates": [ { "geocoderStatus": "OK", "types": [ "locality", "political" ], "partialMatch": false, "placeId": "ChIJC8sZCqULj4ARVJvnNcic_V4", "intermediateWaypointRequestIndex": 0 } ] }