맞춤 코드 사용: 위치가 백엔드를 통해 전달되거나 Android 또는 iOS 이외의 기기를 사용하는 경우에 유용합니다. 이 문서에서는 이 접근 방식을 다룹니다.
차량 위치 업데이트를 제공하는 방식과 관계없이 백엔드는 배송 차량이 정류장으로 이동 중일 때와 정류장에 도착했을 때 Fleet Engine을 업데이트해야 합니다. 여기에는 창고 자체가 포함됩니다. Fleet Engine은 이러한 이벤트를 자동으로 감지하지 않습니다.
차량 위치 업데이트 예시
Java gRPC 라이브러리를 사용하여 Fleet Engine에서 차량의 위치를 업데이트하거나 REST를 사용할 수 있습니다.
자바
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,["최종 업데이트: 2025-08-31(UTC)"],[[["\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)"]]