staticfinalStringPROJECT_ID="my-delivery-co-gcp-project";staticfinalStringVEHICLE_ID="vehicle-8241890";DeliveryServiceBlockingStubdeliveryService=DeliveryServiceGrpc.newBlockingStub(channel);// Vehicle settingsStringvehicleName="providers/"+PROJECT_ID+"/deliveryVehicles/"+VEHICLE_ID;DeliveryVehiclemyDeliveryVehicle=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 requestUpdateDeliveryVehicleRequestupdateDeliveryVehicleRequest=UpdateDeliveryVehicleRequest.newBuilder()// No need for the header.setName(vehicleName).setDeliveryVehicle(myDeliveryVehicle).setUpdateMask(FieldMask.newBuilder().addPaths("last_location")).build();try{DeliveryVehicleupdatedDeliveryVehicle=deliveryService.updateDeliveryVehicle(updateDeliveryVehicleRequest);}catch(StatusRuntimeExceptione){Statuss=e.getStatus();switch(s.getCode()){caseNOT_FOUND:break;casePERMISSION_DENIED:break;}return;}
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eBefore making vehicle requests, review the requirements outlined in the Vehicle requests section of the Introduction.\u003c/p\u003e\n"],["\u003cp\u003eProvide vehicle location updates to Fleet Engine at least every minute and at most every 5 seconds, either using the Driver SDK (simplest) or custom code for backend integration or non-Android/iOS devices.\u003c/p\u003e\n"],["\u003cp\u003eYour backend is responsible for notifying Fleet Engine of vehicle status changes, including en route and arrival at stops, as this is not automatically detected.\u003c/p\u003e\n"],["\u003cp\u003eVehicle location updates can be implemented using the Java gRPC library or REST, with required and optional fields for providing accurate location data and timestamps.\u003c/p\u003e\n"]]],["Vehicle location updates in Fleet Engine can be provided via the Driver SDK or custom code, with updates needed every 5 seconds to 1 minute. Backends must update Fleet Engine when vehicles are en route to or arrive at stops, as it doesn't auto-detect these events. Updates, performed using Java gRPC or REST, require specifying `lastLocation` details like coordinates, timestamp, and sensor as `CUSTOMER_SUPPLIED_LOCATION`. Optionally, location accuracy can also be provided. Ensure to read vehicle request requirements beforehand.\n"],null,["# Update a delivery vehicle location\n\n| **Note:** **Before constructing a vehicle request** , read the requirements under [Vehicle requests](/maps/documentation/mobility/fleet-engine/essentials/vehicles#vehicle_requests) in the Introduction.\n\nApproaches\n----------\n\nFor the best performance with Fleet Engine, provide it with a stream of vehicle\nlocation updates at least once every minute and at most once every 5 seconds.\nUse either of the following ways to provide these updates:\n\n- **Use the [Driver SDK](/maps/documentation/mobility/driver-sdk/scheduled)**: Simplest option.\n- **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.\n\nRegardless of how you provide vehicle location updates, your backend is\nresponsible for updating Fleet Engine when a delivery vehicle is enroute to a\nstop and when it arrives at a stop. This includes the depot itself. Fleet Engine\ndoes not detect these events automatically.\n\nUpdate vehicle location examples\n--------------------------------\n\nYou can use the [Java gRPC library](/maps/documentation/mobility/fleet-engine/essentials/client-libraries-tasks#java) to update a vehicle's location in Fleet\nEngine, or use REST. \n\n### Java\n\n static final String PROJECT_ID = \"my-delivery-co-gcp-project\";\n static final String VEHICLE_ID = \"vehicle-8241890\";\n\n DeliveryServiceBlockingStub deliveryService =\n DeliveryServiceGrpc.newBlockingStub(channel);\n\n // Vehicle settings\n String vehicleName = \"providers/\" + PROJECT_ID + \"/deliveryVehicles/\" + VEHICLE_ID;\n DeliveryVehicle myDeliveryVehicle = DeliveryVehicle.newBuilder()\n .setLastLocation(DeliveryVehicleLocation.newBuilder()\n .setSupplementalLocation(LatLng.newBuilder()\n .setLatitude(37.3382)\n .setLongitude(121.8863))\n .setSupplementalLocationTime(now())\n .setSupplementalLocationSensor(DeliveryVehicleLocationSensor.CUSTOMER_SUPPLIED_LOCATION)\n .setSupplementalLocationAccuracy(DoubleValue.of(15.0))) // Optional\n .build();\n\n // DeliveryVehicle request\n UpdateDeliveryVehicleRequest updateDeliveryVehicleRequest =\n UpdateDeliveryVehicleRequest.newBuilder() // No need for the header\n .setName(vehicleName)\n .setDeliveryVehicle(myDeliveryVehicle)\n .setUpdateMask(FieldMask.newBuilder()\n .addPaths(\"last_location\"))\n .build();\n\n try {\n DeliveryVehicle updatedDeliveryVehicle =\n deliveryService.updateDeliveryVehicle(updateDeliveryVehicleRequest);\n } catch (StatusRuntimeException e) {\n Status s = e.getStatus();\n switch (s.getCode()) {\n case NOT_FOUND:\n break;\n case PERMISSION_DENIED:\n break;\n }\n return;\n }\n\n### REST\n\n PATCH https://fleetengine.googleapis.com/v1/providers/\u003cproject_id\u003e/deliveryVehicles/\u003cid\u003e?updateMask=last_location\n\n### Request details\n\nThe request body must contain a `DeliveryVehicle` entity that specifies\nfields as follows:\n\n- Required fields:\n\n | Field | Value |\n |-------------------------------------------|------------------------------------------------------------|\n | `lastLocation.supplementalLocation` | The location of the vehicle. |\n | `lastLocation.supplementalLocationTime` | The last known timestamp the vehicle was at this location. |\n | `lastLocation.supplementalLocationSensor` | Should be populated with `CUSTOMER_SUPPLIED_LOCATION`. |\n\n \u003cbr /\u003e\n\n- Optional fields:\n\n | Field | Value |\n |---------------------------------------------|-----------------------------------------------|\n | `lastLocation.supplementalLocationAccuracy` | Accuracy of the supplied location, in meters. |\n\n \u003cbr /\u003e\n\n # Set JWT, PROJECT_ID, VEHICLE_ID, TASK1_ID, and TASK2_ID in the local\n # environment\n curl -X PATCH \"https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/deliveryVehicles/${VEHICLE_ID}?updateMask=remainingVehicleJourneySegments\" \\\n -H \"Content-type: application/json\" \\\n -H \"Authorization: Bearer ${JWT}\" \\\n --data-binary @- \u003c\u003c EOM\n {\n \"lastLocation\": {\n \"supplementalLocation\": {\"latitude\": 12.1, \"longitude\": 14.5},\n \"supplementalLocationTime\": \"$(date -u --iso-8601=seconds)\",\n \"supplementalLocationSensor\": \"CUSTOMER_SUPPLIED_LOCATION\",\n \"supplementalLocationAccuracy\": 15\n }\n }\n EOM\n\nWhat's next\n-----------\n\n- [Get a delivery vehicle](/maps/documentation/mobility/fleet-engine/essentials/vehicles/scheduled-tasks-get-vehicle)"]]