> [!NOTE]
> **Note:** **Before constructing a vehicle request** , read the requirements under [Vehicle requests](https://developers.google.com/maps/documentation/mobility/fleet-engine/essentials/vehicles.md.txt#vehicle_requests) in the Introduction.

## Approaches

For the best performance with Fleet Engine, provide it with a stream of vehicle
location updates at least once every minute and at most once every 5 seconds.
Use either of the following ways to provide these updates:

- **Use the [Driver SDK](https://developers.google.com/maps/documentation/mobility/driver-sdk/scheduled.md.txt)**: Simplest option.
- **Use custom code**: useful if locations are relayed through your backend, or if you use devices other than Android or iOS. This document covers that approach.

Regardless of how you provide vehicle location updates, your backend is
responsible for updating Fleet Engine when a delivery vehicle is enroute to a
stop and when it arrives at a stop. This includes the depot itself. Fleet Engine
does not detect these events automatically.

## Update vehicle location examples

To update a vehicle's location in Fleet Engine, you can use the
[Java gRPC library](https://developers.google.com/maps/documentation/mobility/fleet-engine/essentials/client-libraries-tasks.md.txt#java) or REST, as shown in the following example. For a
complete list of supported languages, see
[Client libraries for scheduled task services](https://developers.google.com/maps/documentation/mobility/fleet-engine/essentials/client-libraries-tasks.md.txt).

### Java

```java
  static final String PROJECT_ID = "my-delivery-co-gcp-project";
  static final String VEHICLE_ID = "vehicle-8241890";

  DeliveryServiceBlockingStub deliveryService =
    DeliveryServiceGrpc.newBlockingStub(channel);

  // Vehicle settings
  String vehicleName = "providers/" + PROJECT_ID + "/deliveryVehicles/" + VEHICLE_ID;
  DeliveryVehicle myDeliveryVehicle = DeliveryVehicle.newBuilder()
      .setLastLocation(DeliveryVehicleLocation.newBuilder()
          .setSupplementalLocation(LatLng.newBuilder()
              .setLatitude(37.3382)
              .setLongitude(121.8863))
          .setSupplementalLocationTime(now())
          .setSupplementalLocationSensor(DeliveryVehicleLocationSensor.CUSTOMER_SUPPLIED_LOCATION)
          .setSupplementalLocationAccuracy(DoubleValue.of(15.0)))  // Optional
      .build();

  // DeliveryVehicle request
  UpdateDeliveryVehicleRequest updateDeliveryVehicleRequest =
    UpdateDeliveryVehicleRequest.newBuilder()  // No need for the header
        .setName(vehicleName)
        .setDeliveryVehicle(myDeliveryVehicle)
        .setUpdateMask(FieldMask.newBuilder()
            .addPaths("last_location"))
        .build();

  try {
    DeliveryVehicle updatedDeliveryVehicle =
        deliveryService.updateDeliveryVehicle(updateDeliveryVehicleRequest);
  } catch (StatusRuntimeException e) {
    Status s = e.getStatus();
    switch (s.getCode()) {
       case NOT_FOUND:
         break;
       case PERMISSION_DENIED:
         break;
    }
    return;
  }
```

### REST

```html
PATCH https://fleetengine.googleapis.com/v1/providers/<project_id>/deliveryVehicles/<id>?updateMask=last_location
```

### Request details

The request body must contain a `DeliveryVehicle` entity that specifies
fields as follows:

- Required fields:

  | Field | Value |
  |---|---|
  | `lastLocation.supplementalLocation` | The location of the vehicle. |
  | `lastLocation.supplementalLocationTime` | The last known timestamp the vehicle was at this location. |
  | `lastLocation.supplementalLocationSensor` | Should be populated with `CUSTOMER_SUPPLIED_LOCATION`. |

  <br />

- Optional fields:

  | Field | Value |
  |---|---|
  | `lastLocation.supplementalLocationAccuracy` | Accuracy of the supplied location, in meters. |

  <br />

```s
  # Set JWT, PROJECT_ID, VEHICLE_ID, TASK1_ID, and TASK2_ID in the local
  # environment
  curl -X PATCH "https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/deliveryVehicles/${VEHICLE_ID}?updateMask=remainingVehicleJourneySegments" \
    -H "Content-type: application/json" \
    -H "Authorization: Bearer ${JWT}" \
    --data-binary @- << EOM
  {
    "lastLocation": {
      "supplementalLocation": {"latitude": 12.1, "longitude": 14.5},
      "supplementalLocationTime": "$(date -u --iso-8601=seconds)",
      "supplementalLocationSensor": "CUSTOMER_SUPPLIED_LOCATION",
      "supplementalLocationAccuracy": 15
    }
  }
  EOM
```

## What's next

- [Get a delivery vehicle](https://developers.google.com/maps/documentation/mobility/fleet-engine/essentials/vehicles/scheduled-tasks-get-vehicle.md.txt)