Waypoints may include location modifiers to change how routes are calculated, including
settings for heading
and sideOfRoad
.
Specify the vehicle heading
To define a waypoint, specify the geographic location using latitude/longitude coordinates. You can also specify the direction you want the vehicle to head when it arrives at each waypoint. Use this feature to ensure that the vehicle arrives on the same side of the road as the consumer waiting to be picked up. When a heading is not specified, the vehicle can arrive on the wrong side of the road.
Heading values are numbers that align with the compass directions, and therefore range from zero to 359. For example, a value of 0 indicates a heading direction of due North.
// Mountain View, CA const originLatLng = {lat: 37.422000, lng: -122.084058}; // San Francisco, CA const destinationLatLng = {lat: 37.774929, lng: -122.419415}; // Half Moon Bay, CA const viaLatLng = {lat: 37.450733, lng: -122.430281, heading: 330}; // Define a computeRoutes request. const requestWithLatLngs = { origin: originLatLng, destination: destinationLatLng, intermediates: [ {location: viaLatLng} ], fields: ['path'], };
Specify a the side of road preference
A location defined by a latitude and longitude pair can correspond to a specific side of a road. However, to support route optimization, a route can still set a stopover to be on the opposite side of the road from the specified location.
Waypoints support the sideOfRoad
property, which indicates that the waypoint
location has a preference for the vehicle to stop at the same side of road as specified by the
location.
Specify that the route uses the preferred side of the road by setting the sideOfRoad
property to true
. The route then passes through the location so that the vehicle
can stop at the side of road that the location is biased towards.
The following example shows how to set sideOfRoad
for a waypoint:
const sideOfRoadLatLng = { location: { lat: 37.450733, lng: -122.430281, }, sideOfRoad: true, };