تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يوضّح هذا القسم كيفية تجهيز المركبة للرحلات. يجب إكمال
كل خطوة من الخطوات التالية قبل أن تتمكّن الخلفية من مطابقة مركبة مع رحلة.
إعداد المستمعين
بعد تهيئة Driver SDK وإنشاء مثيل GMTDRidesharingDriverAPI، يمكنك إعداد أدوات معالجة الأحداث لتتبُّع نجاح أو تعذُّر عمليات تعديل المركبة التي يتم إرسالها إلى Fleet Engine والخادم الخلفي. ويمكن أن تؤدي أدوات معالجة الأحداث هذه إلى
تفعيل إجراءات داخل تطبيق السائق، مثل إرسال إشعار إلى السائق في حال تعذّر
التواصل مع الخلفية.
الاستماع إلى أحداث تحديث المركبة
عندما يفعّل السائق ميزة تعديل الموقع الجغرافي في تطبيق السائق، ترسل حزمة تطوير البرامج (SDK) الخاصة بالسائق تحديثات منتظمة عن المركبة إلى Fleet Engine وخادم الخلفية الخاص بالعميل من خلال الفئة GMTDVehicleReporter. يمكنك جعل التطبيق يستجيب لأحداث التحديث من خلال إعداد بروتوكول GMTDVehicleReporterListener.
باستخدام GMTDVehicleReporterListener، يمكنك التعامل مع الأحداث التالية:
تُعلم هذه الطريقة المستمع بأنّه تعذّر تعديل المركبة. طالما أنّ السائق فعّل إذن الحصول على آخر المعلومات عن الموقع الجغرافي، سيستمر صف GMTDVehicleReporter في إرسال أحدث البيانات إلى Fleet Engine.
توضّح الأمثلة التالية كيفية إعداد GMTDVehicleReporterListener للتعامل مع هذه الأحداث:
Swift
importGoogleRidesharingDriverprivateletproviderID="INSERT_YOUR_PROVIDER_ID"classSampleViewController:UIViewController,GMTDVehicleReporterListener{privateletmapView:GMSMapViewoverridefuncviewDidLoad(){// Assumes you have implemented the sample code up to this step.ridesharingDriverAPI.vehicleReporter.add(self)}funcvehicleReporter(_vehicleReporter:GMTDVehicleReporter,didSucceedvehicleUpdate:GMTDVehicleUpdate){// Handle update succeeded.}funcvehicleReporter(_vehicleReporter:GMTDVehicleReporter,didFailvehicleUpdate:GMTDVehicleUpdate,withErrorerror:Error){// Handle update failed.}}
Objective-C
/** * SampleViewController.h */@interfaceSampleViewController : UIViewController<GMTDVehicleReporterListener>@end/** * SampleViewController.m */#import "SampleViewController.h"#import "SampleAccessTokenProvider.h"#import <GoogleRidesharingDriver/GoogleRidesharingDriver.h>staticNSString*constPROVIDER_ID=@"INSERT_YOUR_PROVIDER_ID";@implementationSampleViewController{GMSMapView*_mapView;}-(void)viewDidLoad{// Assumes you have implemented the sample code up to this step.[ridesharingDriverAPI.vehicleReporteraddListener:self];}-(void)vehicleReporter:(GMTDVehicleReporter*)vehicleReporterdidSucceedVehicleUpdate:(GMTDVehicleUpdate*)vehicleUpdate{// Handle update succeeded.}-(void)vehicleReporter:(GMTDVehicleReporter*)vehicleReporterdidFailVehicleUpdate:(GMTDVehicleUpdate*)vehicleUpdatewithError:(NSError*)error{// Handle update failed.}@end
الاستماع إلى التحديثات بشأن الموقع الجغرافي للمركبة
توفّر حزمة تطوير البرامج للتنقّل إشعارات التحديث بشأن الموقع الجغرافي إلى حزمة تطوير البرامج للسائقين من خلال الفئة GMSRoadSnappedLocationProvider. لتلقّي هذه الإشعارات، عليك إعداد GMTDVehicleReporter كجهاز استماع.
Swift
importGoogleRidesharingDriverprivateletproviderID="INSERT_YOUR_PROVIDER_ID"classSampleViewController:UIViewController,GMTDVehicleReporterListener{privateletmapView:GMSMapViewoverridefuncviewDidLoad(){// Assumes you have implemented the sample code up to this step.ifletroadSnappedLocationProvider=mapView.roadSnappedLocationProvider{roadSnappedLocationProvider.add(ridesharingDriverAPI.vehicleReporter)roadSnappedLocationProvider.startUpdatingLocation()}}}
Objective-C
/** * SampleViewController.h */@interfaceSampleViewController : UIViewController<GMTDVehicleReporterListener>@end/** * SampleViewController.m */#import "SampleViewController.h"#import "SampleAccessTokenProvider.h"#import <GoogleRidesharingDriver/GoogleRidesharingDriver.h>staticNSString*constPROVIDER_ID=@"INSERT_YOUR_PROVIDER_ID";@implementationSampleViewController{GMSMapView*_mapView;}-(void)viewDidLoad{// Assumes you have implemented the sample code up to this step.[_mapView.roadSnappedLocationProvideraddListener:ridesharingDriverAPI.vehicleReporter];[_mapView.roadSnappedLocationProviderstartUpdatingLocation];}@end
تفعيل تحديثات الموقع الجغرافي
لتفعيل تحديثات الموقع الجغرافي، اضبط locationTrackingEnabled على true on
GMTDVehicleReporter في تطبيق السائق. بعد ذلك، يرسل الصف GMTDVehicleReporter
تلقائيًا تحديثات الموقع الجغرافي إلى Fleet Engine. بعد أن تتطابق خدمات Fleet Engine وخلفية العميل وتُعيّن المركبة إلى رحلة، يرسل الصف GMTDVehicleReporter تلقائيًا تعديلات على المسار عندما يكون GMSNavigator في وضع التنقّل، أي عندما يتم ضبط وجهة من خلال setDestinations.
تضبط حزمة تطوير البرامج Driver SDK المسار ليتطابق مع مسار التنقّل الحالي للسائق. لضمان دقة تحديثات الموقع الجغرافي، اضبط نقطة الطريق في setDestinations لتتطابق مع الوجهة في Fleet Engine.
يوضّح المثال التالي كيفية تفعيل تعديلات الموقع الجغرافي:
Swift
importGoogleRidesharingDriverprivateletproviderID="INSERT_YOUR_PROVIDER_ID"classSampleViewController:UIViewController,GMTDVehicleReporterListener{privateletmapView:GMSMapViewoverridefuncviewDidLoad(){// Assumes you have implemented the sample code up to this step.ridesharingDriverAPI.vehicleReporter.locationTrackingEnabled=true}}
Objective-C
/** * SampleViewController.m */#import "SampleViewController.h"#import "SampleAccessTokenProvider.h"#import <GoogleRidesharingDriver/GoogleRidesharingDriver.h>staticNSString*constPROVIDER_ID=@"INSERT_YOUR_PROVIDER_ID";@implementationSampleViewController{GMSMapView*_mapView;}-(void)viewDidLoad{// Assumes you have implemented the sample code up to this step.ridesharingDriverAPI.vehicleReporter.locationTrackingEnabled=YES;}@end
تحديد الفاصل الزمني للتعديل
بشكلٍ تلقائي، عند ضبط locationTrackingEnabled على true، ترسل حزمة تطوير البرامج Driver SDK تحديثات الرحلات والمركبات إلى Fleet Engine كل 10 ثوانٍ. يمكنك تغيير فاصل التحديث باستخدام locationUpdateInterval إلى فاصل تحديث يبلغ 5 ثوانٍ كحد أدنى أو 60 ثانية كحد أقصى. قد تؤدي عمليات التحديث المتكرّرة إلى بطء الاستجابة للطلبات وحدوث أخطاء.
ضبط حالة المركبة على "متصلة"
بعد تفعيل ميزة "تعديلات الموقع الجغرافي"، اضبط حالة المركبة على ONLINE لجعل المركبة متاحة لطلبات البحث في Fleet Engine.
توضّح الأمثلة التالية كيفية ضبط حالة المركبة على ONLINE. للحصول على التفاصيل، يُرجى الاطّلاع على updateVehicleState.
Swift
importGoogleRidesharingDriverprivateletproviderID="INSERT_YOUR_PROVIDER_ID"classSampleViewController:UIViewController,GMTDVehicleReporterListener{privateletmapView:GMSMapViewoverridefuncviewDidLoad(){// Assumes you have implemented the sample code up to this step.ridesharingDriverAPI.vehicleReporter.update(.online)}}
Objective-C
#import "SampleViewController.h"#import "SampleAccessTokenProvider.h"#import <GoogleRidesharingDriver/GoogleRidesharingDriver.h>staticNSString*constPROVIDER_ID=@"INSERT_YOUR_PROVIDER_ID";@implementationSampleViewController{GMSMapView*_mapView;}-(void)viewDidLoad{// Assumes you have implemented the sample code up to this step.[ridesharingDriverAPI.vehicleReporterupdateVehicleState:GMTDVehicleStateOnline];}@end
تاريخ التعديل الأخير: 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, drivers must set up listeners, enable location updates, and set the vehicle state to online using the Driver SDK.\u003c/p\u003e\n"],["\u003cp\u003eEvent listeners monitor vehicle updates sent to Fleet Engine, triggering actions like driver notifications upon communication failures.\u003c/p\u003e\n"],["\u003cp\u003eEnabling location updates requires setting \u003ccode\u003elocationTrackingEnabled\u003c/code\u003e to \u003ccode\u003etrue\u003c/code\u003e, allowing the Driver SDK to send regular location and state updates.\u003c/p\u003e\n"],["\u003cp\u003eDrivers must set the vehicle state to \u003ccode\u003eONLINE\u003c/code\u003e to make the vehicle discoverable for trip assignments in Fleet Engine.\u003c/p\u003e\n"],["\u003cp\u003eThe Driver SDK sets the route dynamically to match the driver's navigation path, requiring waypoints to align with Fleet Engine's destination for accurate location updates.\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 listeners\n----------------\n\nAfter initializing the Driver SDK and creating a `GMTDRidesharingDriverAPI`\ninstance, you can set up event listeners to monitor the success or failure of\nvehicle updates sent to Fleet Engine and your backend. These listeners can\ntrigger actions within your driver app, such as notifying the driver if\ncommunication with your backend fails.\n\n### Listen for vehicle update events\n\nWhen the driver enables location updates in the driver app, the Driver SDK\nsends regular vehicle updates to Fleet Engine and the customer\nbackend through the `GMTDVehicleReporter` class. You can have the app respond\nto update events by setting up the `GMTDVehicleReporterListener` protocol.\n\nWith `GMTDVehicleReporterListener`, you can handle the following events:\n\n- [`vehicleReporter:didSucceedVehicleUpdate`](/maps/documentation/mobility/driver-sdk/on-demand/reference/ios/protocol_g_m_t_d_vehicle_reporter_listener-p#a3882e0ff1b3e89d47f501c194818baf5)\n\n Informs the Driver app that the backend services successfully received the\n vehicle location and state update.\n- [`vehicleReporter:didFailVehicleUpdate:withError`](/maps/documentation/mobility/driver-sdk/on-demand/reference/ios/protocol_g_m_t_d_vehicle_reporter_listener-p#a494bc226e6a36c4a4528d35919ce5085)\n\n Informs the listener that a vehicle update failed. As long as the driver has\n location updates enabled, the `GMTDVehicleReporter` class continues to send\n the latest data to Fleet Engine.\n\nThe following examples show how to set up `GMTDVehicleReporterListener` to\nhandle these events: \n\n### Swift\n\n import GoogleRidesharingDriver\n\n private let providerID = \"INSERT_YOUR_PROVIDER_ID\"\n\n class SampleViewController: UIViewController, GMTDVehicleReporterListener {\n private let mapView: GMSMapView\n\n override func viewDidLoad() {\n // Assumes you have implemented the sample code up to this step.\n ridesharingDriverAPI.vehicleReporter.add(self)\n }\n\n func vehicleReporter(_ vehicleReporter: GMTDVehicleReporter, didSucceed vehicleUpdate: GMTDVehicleUpdate) {\n // Handle update succeeded.\n }\n\n func vehicleReporter(_ vehicleReporter: GMTDVehicleReporter, didFail vehicleUpdate: GMTDVehicleUpdate, withError error: Error) {\n // Handle update failed.\n }\n }\n\n### Objective-C\n\n /**\n * SampleViewController.h\n */\n @interface SampleViewController : UIViewController\u003cGMTDVehicleReporterListener\u003e\n @end\n\n /**\n * SampleViewController.m\n */\n #import \"SampleViewController.h\"\n #import \"SampleAccessTokenProvider.h\"\n #import \u003cGoogleRidesharingDriver/GoogleRidesharingDriver.h\u003e\n\n static NSString *const PROVIDER_ID = @\"INSERT_YOUR_PROVIDER_ID\";\n\n @implementation SampleViewController {\n GMSMapView *_mapView;\n }\n\n - (void)viewDidLoad {\n // Assumes you have implemented the sample code up to this step.\n [ridesharingDriverAPI.vehicleReporter addListener:self];\n }\n\n - (void)vehicleReporter:(GMTDVehicleReporter *)vehicleReporter didSucceedVehicleUpdate:(GMTDVehicleUpdate *)vehicleUpdate {\n // Handle update succeeded.\n }\n\n - (void)vehicleReporter:(GMTDVehicleReporter *)vehicleReporter didFailVehicleUpdate:(GMTDVehicleUpdate *)vehicleUpdate withError:(NSError *)error {\n // Handle update failed.\n }\n\n @end\n\n### Listen for vehicle location updates\n\nThe Navigation SDK provides location updates to the Driver SDK through the\n`GMSRoadSnappedLocationProvider` class. To receive those updates, you must set\nup the `GMTDVehicleReporter` as a listener.\n**Note:** If the device has not moved since the last location update, the `GMSRoadSnappedLocationProvider` class does not send location updates continuously for better performance. For example, if a driver is waiting idle in the car. If you want to send a new location update, and have set `GMTDVehicleReporter` as a listener after calling `startUpdatingLocation` on `GMSRoadSnappedLocationProvider`, you need to stop and start `GMSRoadSnappedLocationProvider`. \n\n### Swift\n\n import GoogleRidesharingDriver\n\n private let providerID = \"INSERT_YOUR_PROVIDER_ID\"\n\n class SampleViewController: UIViewController, GMTDVehicleReporterListener {\n private let mapView: GMSMapView\n\n override func viewDidLoad() {\n // Assumes you have implemented the sample code up to this step.\n if let roadSnappedLocationProvider = mapView.roadSnappedLocationProvider {\n roadSnappedLocationProvider.add(ridesharingDriverAPI.vehicleReporter)\n roadSnappedLocationProvider.startUpdatingLocation()\n }\n }\n }\n\n### Objective-C\n\n /**\n * SampleViewController.h\n */\n @interface SampleViewController : UIViewController\u003cGMTDVehicleReporterListener\u003e\n @end\n\n /**\n * SampleViewController.m\n */\n #import \"SampleViewController.h\"\n #import \"SampleAccessTokenProvider.h\"\n #import \u003cGoogleRidesharingDriver/GoogleRidesharingDriver.h\u003e\n\n static NSString *const PROVIDER_ID = @\"INSERT_YOUR_PROVIDER_ID\";\n\n @implementation SampleViewController {\n GMSMapView *_mapView;\n }\n\n - (void)viewDidLoad {\n // Assumes you have implemented the sample code up to this step.\n [_mapView.roadSnappedLocationProvider addListener:ridesharingDriverAPI.vehicleReporter];\n [_mapView.roadSnappedLocationProvider startUpdatingLocation];\n }\n\n @end\n\nEnable location updates\n-----------------------\n\nTo enable location updates, set `locationTrackingEnabled` to `true` on\n`GMTDVehicleReporter` in the driver app. Then the `GMTDVehicleReporter` class\nautomatically sends location updates to Fleet Engine. After the Fleet Engine and\ncustomer backend services match and assign the vehicle to a trip, the\n`GMTDVehicleReporter` class sends route updates automatically when the\n`GMSNavigator` is in navigation mode, which is when a destination is set through\n`setDestinations`.\n\nThe Driver SDK sets the route to match the driver's current navigation path. To\nensure accurate location updates, set the waypoint in `setDestinations` to match\nthe destination in Fleet Engine.\n\nThe following example shows how to enable location updates: \n\n### Swift\n\n import GoogleRidesharingDriver\n\n private let providerID = \"INSERT_YOUR_PROVIDER_ID\"\n\n class SampleViewController: UIViewController, GMTDVehicleReporterListener {\n private let mapView: GMSMapView\n\n override func viewDidLoad() {\n // Assumes you have implemented the sample code up to this step.\n ridesharingDriverAPI.vehicleReporter.locationTrackingEnabled = true\n }\n }\n\n### Objective-C\n\n /**\n * SampleViewController.m\n */\n #import \"SampleViewController.h\"\n #import \"SampleAccessTokenProvider.h\"\n #import \u003cGoogleRidesharingDriver/GoogleRidesharingDriver.h\u003e\n\n static NSString *const PROVIDER_ID = @\"INSERT_YOUR_PROVIDER_ID\";\n\n @implementation SampleViewController {\n GMSMapView *_mapView;\n }\n\n - (void)viewDidLoad {\n // Assumes you have implemented the sample code up to this step.\n ridesharingDriverAPI.vehicleReporter.locationTrackingEnabled = YES;\n }\n\n @end\n\n### Set the update interval\n\nBy default, when you set `locationTrackingEnabled` to `true`, the Driver SDK\nsends trip and vehicle updates to Fleet Engine at a 10-second interval. You can\nchange the update interval with `locationUpdateInterval` to a minimum update\ninterval of 5 seconds or a maximum of 60 seconds. More frequent updates may\nresult in slower requests and errors.\n\nSet the vehicle state to online\n-------------------------------\n\nAfter you enable location updates, set the vehicle state to `ONLINE` to make the\nvehicle available for search queries in Fleet Engine.\n\nThe following examples show how to set the vehicle state to `ONLINE`. For\ndetails, see [`updateVehicleState`](/maps/documentation/mobility/driver-sdk/on-demand/reference/ios/interface_g_m_t_d_vehicle_reporter). \n\n### Swift\n\n import GoogleRidesharingDriver\n\n private let providerID = \"INSERT_YOUR_PROVIDER_ID\"\n\n class SampleViewController: UIViewController, GMTDVehicleReporterListener {\n private let mapView: GMSMapView\n\n override func viewDidLoad() {\n // Assumes you have implemented the sample code up to this step.\n ridesharingDriverAPI.vehicleReporter.update(.online)\n }\n }\n\n### Objective-C\n\n #import \"SampleViewController.h\"\n #import \"SampleAccessTokenProvider.h\"\n #import \u003cGoogleRidesharingDriver/GoogleRidesharingDriver.h\u003e\n\n static NSString *const PROVIDER_ID = @\"INSERT_YOUR_PROVIDER_ID\";\n\n @implementation SampleViewController {\n GMSMapView *_mapView;\n }\n\n - (void)viewDidLoad {\n // Assumes you have implemented the sample code up to this step.\n [ridesharingDriverAPI.vehicleReporter\n updateVehicleState:GMTDVehicleStateOnline];\n }\n\n @end\n\nWhat's next\n-----------\n\n[Set the trip details](/maps/documentation/mobility/driver-sdk/on-demand/ios/trip-details)"]]