تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يوضّح هذا القسم كيفية تجهيز المركبة للرحلات. يجب إكمال
كل خطوة من الخطوات التالية قبل أن تتمكّن الخلفية من مطابقة مركبة مع رحلة.
إعداد المستمع
بما أنّ حزمة تطوير البرامج (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());
تفعيل تحديثات الموقع الجغرافي
بعد إعداد أداة الاستماع، فعِّل تحديثات الموقع الجغرافي باتّباع الخطوات التالية:
تُرسِل حزمة تطوير البرامج Driver SDK تلقائيًا إشعارات التحديث بشأن الموقع الجغرافي كل 10 ثوانٍ عندما تكون حالة المركبة ONLINE. يمكنك تغيير هذا الفاصل الزمني من خلال reporter.setLocationReportingInterval(long, TimeUnit). الحد الأدنى لفترة التعديل المتاحة هو 5 ثوانٍ. قد تؤدي التحديثات المتكررة إلى بطء الطلبات وحدوث أخطاء.
ضبط حالة المركبة على "متصلة"
عند تفعيل ميزة تعديلات الموقع الجغرافي، يمكنك ضبط حالة المركبة على ONLINE لجعل المركبة متاحة لطلبات البحث SearchVehicles في Fleet Engine. ترسل حزمة تطوير البرامج Driver SDK حالة المركبة المعدَّلة مع إشعارات التحديث بشأن الموقع الجغرافي.
يمكنك ضبط حالة المركبة مباشرةً في Driver SDK أو في خادم Fleet Engine. لمزيد من المعلومات، يُرجى الاطّلاع على تعديل مركبة.
توضّح الأمثلة التالية كيفية ضبط حالة المركبة على "متصل" في Driver SDK:
تاريخ التعديل الأخير: 2025-09-05 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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-05 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\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)"]]