> [!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.

For the best performance with Fleet Engine, provide it with a stream of vehicle
location updates. Use either of the following ways to provide these updates:

1. **Use the Driver SDK** : simplest option. See the Driver SDK documentation for [Android](https://developers.google.com/maps/documentation/mobility/driver-sdk/on-demand/android/minimum-requirements.md.txt) or [iOS](https://developers.google.com/maps/documentation/mobility/driver-sdk/on-demand/ios/minimum-requirements.md.txt).
2. **Use custom code**: useful if locations are relayed through your backend, or if you use devices other than Android or iOS. This guide covers that approach.

If not using the Driver SDK to update the vehicle's location, you can make a
direct call to Fleet Engine with the vehicle's location. For any active vehicle,
Fleet Engine expects a location update at least once every minute and at most
once every 5 seconds. These updates require only *Fleet Engine Driver SDK User*
privileges.

## Update vehicle location example

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

### Java

```java
static final String PROJECT_ID = "project-id";
static final String VEHICLE_ID = "vid-8241890";

VehicleServiceBlockingStub vehicleService = VehicleService.newBlockingStub(channel);

String vehicleName = "providers/" + PROJECT_ID + "/vehicles/" + VEHICLE_ID;
Vehicle updatedVehicle = Vehicle.newBuilder()
    .setLastLocation(VehicleLocation.newBuilder()
        .setSupplementalLocation(LatLng.newBuilder()
            .setLatitude(37.3382)
            .setLongitude(121.8863))
        .setSupplementalLocationTime(now())
        .setSupplementalLocationSensor(LocationSensor.CUSTOMER_SUPPLIED_LOCATION)
        .setSupplementalLocationAccuracy(DoubleValue.of(15.0)))  // Optional
    .build();

UpdateVehicleRequest updateVehicleRequest = UpdateVehicleRequest.newBuilder()
    .setName(vehicleName)
    .setVehicle(updatedVehicle)
    .setUpdateMask(FieldMask.newBuilder()
        .addPaths("last_location"))
    .build();

try {
  Vehicle updatedVehicle =
      vehicleService.updateVehicle(updateVehicleRequest);
} catch (StatusRuntimeException e) {
  Status s = e.getStatus();
  switch (s.getCode()) {
    case NOT_FOUND:
      // Most implementations will call CreateVehicle in this case
      break;
    case PERMISSION_DENIED:
      break;
  }
  return;
}
// If no Exception, Vehicle updated successfully.
```

### REST

```bash
curl -X PUT \
  "https://fleetengine.googleapis.com/v1/providers/project-id/vehicles/vid-8241890?updateMask=last_location" \
  -H "Authorization: Bearer $JWT" \
  -H "Content-Type: application/json" \
  --data-binary @- << EOM
{
    "supplementalLocation": {"latitude": 12.1, "longitude": 14.5},
    "supplementalLocationTime": "$(date -u --iso-8601=seconds)",
    "supplementalLocationSensor": "CUSTOMER_SUPPLIED_LOCATION",
    "supplementalLocationAccuracy": 15
}
EOM
```

See [providers.vehicles.update](https://developers.google.com/maps/documentation/mobility/fleet-engine/reference/trips/rest/v1/providers.vehicles/update.md.txt) reference.

## What's next

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