<br />

> [!WARNING]
> This product or feature is Experimental (pre-GA). Pre-GA products and features might have limited support, and changes to pre-GA products and features might not be compatible with other pre-GA versions. Pre-GA Offerings are covered by the [Google
> Maps Platform Service Specific Terms](https://cloud.google.com/maps-platform/terms/maps-service-terms). For more information, see the [launch stage descriptions](https://developers.google.com/maps/launch-stages.md.txt).

<br />

![U-turn avoidance is present in `ShipmentModel.Shipment` in the pickups and deliveries objects.](https://developers.google.com/static/maps/tt/route-optimization/experimental/u-turn-avoidance/u-turn-avoidance.svg)

U-turn avoidance is a route optimization feature that prevents vehicles from
turning around at the specific pickup or delivery location of a visit. By
setting u-turn avoidance, you specify that the vehicle should face the same
direction when it arrives and when it leaves a visit location.

U-turn avoidance works in the following way:

1. You set the u-turn avoidance property on a specific visit.
2. The API considers both directions of travel on two-way roads and chooses the most optimal path.
3. The API generates a route where the vehicle arrives and leaves without making a u-turn at the visit location. The driver may need to cross the road to reach this location.

This property is ideal for situations where making a u-turn is difficult or
impossible due to vehicle size, traffic signs, or usual traffic conditions.

## Properties

The u-turn avoidance property is defined within the [`VisitRequest`](https://developers.google.com/maps/tt/route-optimization/experimental/u-turn-avoidance/reference/rest/v1/ShipmentModel.md.txt#VisitRequest) object.
This object is used inside the [`pickups`](https://developers.google.com/maps/tt/route-optimization/experimental/u-turn-avoidance/reference/rest/v1/ShipmentModel.md.txt#Shipment.FIELDS.pickups) and [`deliveries`](https://developers.google.com/maps/tt/route-optimization/experimental/u-turn-avoidance/reference/rest/v1/ShipmentModel.md.txt#Shipment.FIELDS.deliveries) arrays of a
shipment.

| Property | Type | Description |
|---|---|---|
| [`avoidUTurns`](https://developers.google.com/maps/tt/route-optimization/experimental/u-turn-avoidance/reference/rest/v1/ShipmentModel.md.txt#VisitRequest.FIELDS.avoid_u_turns) | boolean | When set to `true`, the API prevents the vehicle from making a u-turn at this visit location. The vehicle will arrive and leave facing the same direction. |

## Examples

This section covers two types of examples:

- Code samples that illustrate the structure of u-turn avoidance.
- A request example that includes the feature.

### Code samples

The following example shows the structure of[`avoidUTurns`](https://developers.google.com/maps/tt/route-optimization/experimental/u-turn-avoidance/reference/rest/v1/ShipmentModel.md.txt#VisitRequest.FIELDS.avoid_u_turns) within a pickup
and a delivery:

```json
"pickups":[
  {
    "arrivalLocation": {
      "latitude": 37.42506261000996,
      "longitude": -122.09535511930135
    },
    "avoidUTurns": true
  }
],
"deliveries":[
  {
    "arrivalLocation": {
      "latitude": 37.42421503206021,
      "longitude": -122.09526063135228
    },
    "avoidUTurns": true
  }
]
```

### Request example

The following example shows a basic [`optimizeTours`](https://developers.google.com/maps/tt/route-optimization/experimental/u-turn-avoidance/reference/rest/v1/projects/optimizeTours.md.txt) request that
incorporates u-turn avoidance. This request includes the following elements:

- A shipment with a pickup and a delivery inside the `model` object.
- The [`avoidUTurns`](https://developers.google.com/maps/tt/route-optimization/experimental/u-turn-avoidance/reference/rest/v1/ShipmentModel.md.txt#VisitRequest.FIELDS.avoid_u_turns) property set to `true` on both the pickup and delivery locations to prevent the vehicle from changing direction at those stops.

```json
  {
    "model": {
      "shipments":[
        {
          "pickups":[
            {
              "arrivalLocation": {
                "latitude": 37.42506261000996,
                "longitude": -122.09535511930135
              },
              "avoidUTurns": true
            }
          ],
          "deliveries":[
            {
              "arrivalLocation": {
                "latitude": 37.42421503206021,
                "longitude": -122.09526063135228
              },
              "avoidUTurns": true
            }
          ]
        }
      ],
      "vehicles":[
        {
          "travelMode": "DRIVING",
          "costPerKilometer": 1.0
        }
      ]
    }
  }
```

## Avoid u-turns with `sideOfRoad`

While [`sideOfRoad`](https://developers.google.com/maps/tt/route-optimization/experimental/u-turn-avoidance/reference/rest/v1/ShipmentModel.md.txt#Waypoint.FIELDS.side_of_road) is a separate feature, it is closely related to u-turn
avoidance because it prevents many u-turns by routing the vehicle to the side of
the road closest to the destination. This forces the vehicle to approach a
visit location from a specific direction, which eliminates the need
to do a u-turn.

In practice, you should use u-turn avoidance when it is safe to cross the road
on foot to get to the visit location. If crossing the road is
discouraged or not possible, consider setting [`sideOfRoad`](https://developers.google.com/maps/tt/route-optimization/experimental/u-turn-avoidance/reference/rest/v1/ShipmentModel.md.txt#Waypoint.FIELDS.side_of_road) to `true`
instead.

The [`sideOfRoad`](https://developers.google.com/maps/tt/route-optimization/experimental/u-turn-avoidance/reference/rest/v1/ShipmentModel.md.txt#Waypoint.FIELDS.side_of_road) property is defined within a [`Waypoint`](https://developers.google.com/maps/tt/route-optimization/experimental/u-turn-avoidance/reference/rest/v1/ShipmentModel.md.txt#Waypoint) object.

## Interaction with other features

U-turn avoidance interacts with other routing features in the following ways:

- **Side of road:** Setting both [`avoidUTurns`](https://developers.google.com/maps/tt/route-optimization/experimental/u-turn-avoidance/reference/rest/v1/ShipmentModel.md.txt#VisitRequest.FIELDS.avoid_u_turns) and [`sideOfRoad`](https://developers.google.com/maps/tt/route-optimization/experimental/u-turn-avoidance/reference/rest/v1/ShipmentModel.md.txt#Waypoint.FIELDS.side_of_road) to `true` slightly increases the chances of avoiding a u-turn while routing the vehicle to the side of the road closest to the visit location. However, doing so introduces extra complexities related to the restrictions of u-turn avoidance. For most visit locations, setting only one of these properties is enough to avoid u-turns.
- **Injected solutions:** When you use u-turn avoidance, the API response includes an [`injectedSolutionLocationToken`](https://developers.google.com/maps/tt/route-optimization/experimental/u-turn-avoidance/reference/rest/v1/ShipmentRoute.md.txt#Visit.FIELDS.injected_solution_location_token) inside the generated [`ShipmentRoute.Visit`](https://developers.google.com/maps/tt/route-optimization/experimental/u-turn-avoidance/reference/rest/v1/ShipmentRoute.md.txt#Visit) to record which side of the road it selected. If you ever reuse this visit as an injected solution in a future request, you must pass this token back to the API.

## Limitations

U-turn avoidance is a best-effort feature. The API might still include u-turns
in a generated route under the following conditions:

- The travel mode is set to a mode other than `DRIVING`.
- The arrival and departure locations for a specific visit location are different. In this case, the API returns an error.
- The visit is located on a dead-end road, requiring a u-turn to exit.
- The u-turn occurs along the route, rather than at the actual visit location.
- The maneuver is a very sharp turn onto a different road, which the API does not classify as a u-turn.