請上車
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本節說明如何準備車輛以執行排定的工作。您必須完成下列每個步驟,後端才能將車輛與工作配對。
設定接聽程式
由於 Driver SDK 會在背景執行動作,因此請使用 DriverStatusListener
在發生特定事件時觸發通知,例如錯誤、警告或偵錯訊息。錯誤可能是暫時性 (例如 BACKEND_CONNECTIVITY_ERROR
),也可能導致位置資訊更新永久停止。舉例來說,如果收到 VEHICLE_NOT_FOUND
錯誤,表示設定有誤。
以下範例顯示 DriverStatusListener
的實作方式:
class MyStatusListener implements DriverStatusListener {
/** Called when background status is updated, during actions such as location reporting. */
@Override
public void updateStatus(
StatusLevel statusLevel, StatusCode statusCode, String statusMsg, @Nullable Throwable cause) {
// Existing implementation
if (cause != null && cause instanceof StatusRuntimeException) {
if (Status.NOT_FOUND.getCode().equals(cause.getStatus().getCode())) {
// NOT_FOUND gRPC exception thrown by Fleet Engine.
}
}
}
}
DriverContextBuilder.setDriverStatusListener(new MyStatusListener());
啟用位置資訊更新
取得 *VehicleReporter
執行個體後,請按照下列步驟啟用位置資訊更新:
Java
DeliveryVehicleReporter reporter = ...;
reporter.enableLocationTracking();
Kotlin
val reporter = ...
reporter.enableLocationTracking()
(選用) 設定更新間隔
根據預設,Driver SDK 會每隔 10 秒傳送一次位置更新。每次更新位置資訊也代表車輛已連上網路。如要變更間隔,請使用 reporter.setLocationReportingInterval(long, TimeUnit)
。支援的更新間隔最短為 5 秒。更頻繁的更新可能會導致要求速度變慢和發生錯誤。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-09-12 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-12 (世界標準時間)。"],[[["\u003cp\u003eBefore tasks can be assigned, vehicles must be prepared by completing setup steps that enable communication with the backend system.\u003c/p\u003e\n"],["\u003cp\u003eA \u003ccode\u003eDriverStatusListener\u003c/code\u003e is implemented to receive notifications regarding the vehicle's status, including errors, warnings, and debug messages.\u003c/p\u003e\n"],["\u003cp\u003eLocation updates are enabled using the \u003ccode\u003eenableLocationTracking()\u003c/code\u003e method of a \u003ccode\u003e*VehicleReporter\u003c/code\u003e instance, ensuring the backend knows the vehicle's position.\u003c/p\u003e\n"],["\u003cp\u003eOptionally, the frequency of location updates can be customized, but it's recommended to keep it at the default 10-second interval or above to avoid performance issues.\u003c/p\u003e\n"]]],[],null,[]]