이 섹션에서는 차량을 운행에 대비하는 방법을 보여줍니다. 백엔드에서 차량을 여정에 매칭하려면 다음 단계를 모두 완료해야 합니다.
리스너 설정
Driver SDK는 백그라운드에서 작업을 실행하므로 오류, 경고, 디버그 메시지와 같은 특정 이벤트가 발생할 때 DriverStatusListener를 사용하여 알림을 트리거하세요. 오류는 일시적일 수도 있고 (예: BACKEND_CONNECTIVITY_ERROR) 위치 업데이트가 영구적으로 중지될 수도 있습니다. 예를 들어 VEHICLE_NOT_FOUND 오류가 표시되면 구성 오류를 나타냅니다.
다음 예는 DriverStatusListener 구현을 보여줍니다.
classMyStatusListenerimplementsDriverStatusListener{/** Called when background status is updated, during actions such as location reporting. */@OverridepublicvoidupdateStatus(StatusLevelstatusLevel,StatusCodestatusCode,StringstatusMsg,@NullableThrowablecause){// Existing implementationif(cause!=null && causeinstanceofStatusRuntimeException){if(Status.NOT_FOUND.getCode().equals(cause.getStatus().getCode())){// NOT_FOUND gRPC exception thrown by Fleet Engine.}}}}DriverContextBuilder.setDriverStatusListener(newMyStatusListener());
기본적으로 차량 상태가 ONLINE인 경우 Driver SDK는 10초 간격으로 위치 업데이트를 전송합니다. reporter.setLocationReportingInterval(long, TimeUnit)를 사용하여 이 간격을 변경할 수 있습니다. 지원되는 최소 업데이트 간격은 5초입니다. 업데이트를 더 자주 실행하면 요청이 느려지고 오류가 발생할 수 있습니다.
차량 상태를 온라인으로 설정
위치 업데이트를 사용 설정하면 차량 상태를 ONLINE로 설정하여 Fleet Engine에서 SearchVehicles 쿼리에 차량을 사용할 수 있습니다. Driver SDK는 위치 업데이트와 함께 업데이트된 차량 상태를 전송합니다.
Driver SDK 또는 Fleet Engine 서버에서 직접 차량 상태를 설정할 수 있습니다. 자세한 내용은 차량 업데이트를 참고하세요.
[null,null,["최종 업데이트: 2025-08-31(UTC)"],[[["\u003cp\u003eBefore a backend can match a vehicle to a trip, you must set up a listener to handle status updates and errors.\u003c/p\u003e\n"],["\u003cp\u003eEnable location tracking for the vehicle using the \u003ccode\u003eenableLocationTracking()\u003c/code\u003e method and optionally adjust the location update interval.\u003c/p\u003e\n"],["\u003cp\u003eTo make the vehicle discoverable for trip assignments, set its state to \u003ccode\u003eONLINE\u003c/code\u003e using the \u003ccode\u003esetVehicleState()\u003c/code\u003e method after enabling location tracking.\u003c/p\u003e\n"]]],[],null,["# Get the vehicle ready\n\nThis section shows how to get the vehicle ready for trips. You must complete\neach of the following steps before your backend can match a vehicle to a trip.\n\nSet up listener\n---------------\n\nSince the Driver SDK performs actions in the\nbackground, use the `DriverStatusListener` to trigger notifications when certain\nevents occur, such as errors, warnings, or debug messages. Errors can be\ntransient in nature (such as `BACKEND_CONNECTIVITY_ERROR`), or they might\ncause location updates to stop permanently. For example, if you receive a\n`VEHICLE_NOT_FOUND` error, it indicates a configuration error.\n\nThe following example shows a `DriverStatusListener` implementation: \n\n class MyStatusListener implements DriverStatusListener {\n /** Called when background status is updated, during actions such as location reporting. */\n @Override\n public void updateStatus(\n StatusLevel statusLevel, StatusCode statusCode, String statusMsg, @Nullable Throwable cause) {\n // Existing implementation\n\n if (cause != null && cause instanceof StatusRuntimeException) {\n if (Status.NOT_FOUND.getCode().equals(cause.getStatus().getCode())) {\n // NOT_FOUND gRPC exception thrown by Fleet Engine.\n }\n }\n }\n }\n\n DriverContextBuilder.setDriverStatusListener(new MyStatusListener());\n\nEnable location updates\n-----------------------\n\nAfter you set up the listener, enable location updates as follows: \n\n### Java\n\n RidesharingVehicleReporter reporter = ...;\n\n reporter.enableLocationTracking();\n\n### Kotlin\n\n val reporter = ...\n\n reporter.enableLocationTracking()\n\n| **Note:** Calling `reporter.enableLocationTracking()` does not automatically set the vehicle state to `ONLINE`. You must set the vehicle state explicitly. For details, see [Set the vehicle state to online](#state).\n\n### Set the update interval\n\nBy default, the Driver SDK sends location updates at 10-second intervals\ninterval when the vehicle state is `ONLINE`. You can change this interval with\n`reporter.setLocationReportingInterval(long, TimeUnit)`. The minimum supported\nupdate interval is 5 seconds. More frequent updates may result in slower\nrequests and errors.\n\nSet the vehicle state to online\n-------------------------------\n\nWhen you turn on location updates, you can set the vehicle state to `ONLINE` to\nmake the vehicle available for `SearchVehicles` queries in Fleet Engine. The\nDriver SDK sends the updated vehicle state along with the location updates.\n\nYou can set the vehicle state directly in the Driver SDK or in the Fleet Engine\nserver. For more information, see [Update a Vehicle](/maps/documentation/mobility/fleet-engine/essentials/vehicles/on-demand-vehicle-fields#vehicle_state_field).\n\nThe following examples show how to set the vehicle state to online in the Driver\nSDK: \n\n### Java\n\n RidesharingVehicleReporter reporter = ...;\n\n reporter.enableLocationTracking();\n reporter.setVehicleState(VehicleState.ONLINE);\n\n### Kotlin\n\n val reporter = ...\n\n reporter.enableLocationTracking()\n reporter.setVehicleState(VehicleState.ONLINE)\n\n| **Caution:** You need to have location updates turned on before you set the vehicle online. If you try to do this with location updates off, you'll get an `IllegalStateException` error message.\n\nThe `StatusListener` also reports any errors that occur when updating the\nvehicle state.\n\nWhat's next\n-----------\n\n[Set the trip details](/maps/documentation/mobility/driver-sdk/on-demand/android/trip-details)"]]