تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
إعداد المستمعين
بعد تهيئة Driver SDK وإنشاء مثيل GMTDDeliveryDriverAPI، يمكنك إعداد أدوات معالجة الأحداث لتتبُّع نجاح أو تعذُّر عمليات تعديل المركبة التي يتم إرسالها إلى Fleet Engine والخادم الخلفي. ويمكن أن تؤدي أدوات معالجة الأحداث هذه إلى
تفعيل إجراءات داخل تطبيق السائق، مثل إرسال إشعار إلى السائق في حال تعذّر
التواصل مع الخلفية.
الاستماع إلى أحداث تحديث المركبة
عندما يفعّل السائق إشعارات تحديد الموقع الجغرافي في تطبيق السائق، ترسل حزمة تطوير البرامج (SDK) الخاصة بالسائق إشعارات منتظمة بشأن المركبة إلى Fleet Engine وخادم الخلفية الخاص بالعميل من خلال الفئة GMTDDeliveryVehicleReporter. يمكنك ضبط بروتوكول GMTDVehicleReporterListener لكي يستجيب التطبيق لأحداث التحديث.
باستخدام GMTDVehicleReporterListener، يمكنك التعامل مع الأحداث التالية:
vehicleReporter:didSucceedVehicleUpdate
تُعلم هذه الحالة تطبيق السائق بأنّ الخدمات الخلفية قد تلقّت بنجاح معلومات الموقع الجغرافي للمركبة وحالة التحديث.
vehicleReporter:didFailVehicleUpdate:withError
تُعلم هذه الطريقة المستمع بأنّه تعذّر تعديل المركبة. طالما أنّ السائق فعّل إذن الحصول على آخر المعلومات عن الموقع الجغرافي، سيستمر صف GMTDDeliveryVehicleReporter في إرسال أحدث البيانات إلى 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.deliveryDriverAPI.vehicleReporter.add(self)}funcvehicleReporter(_vehicleReporter:GMTDDeliveryVehicleReporter,didSucceedvehicleUpdate:GMTDVehicleUpdate){// Handle update succeeded.}funcvehicleReporter(_vehicleReporter:GMTDDeliveryVehicleReporter,didFailvehicleUpdate:GMTDVehicleUpdate,withErrorerror:Error){// Handle update failed.}}
Objective-C
SampleViewController.h@interfaceSampleViewController : UIViewController<GMTDVehicleReporterListener>@endSampleViewController.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 IMPLEMENTED HAVE THE SAMPLE CODE UP TO THIS STEP.[delivervehicleReporteraddListener:self];}-(void)vehicleReporter:(GMTDDeliveryVehicleReporter*)vehicleReporterdidSucceedVehicleUpdate:(GMTDVehicleUpdate*)vehicleUpdate{// Handle update succeeded.}-(void)vehicleReporter:(GMTDDeliveryVehicleReporter*)vehicleReporterdidFailVehicleUpdate:(GMTDVehicleUpdate*)vehicleUpdatewithError:(NSError*)error{// Handle update failed.}@end
تفعيل تحديثات الموقع الجغرافي
لتفعيل تحديثات الموقع الجغرافي، اضبط locationTrackingEnabled على YES في تطبيق السائق على GMTDDeliveryVehicleReporter. بعد ذلك، يرسل الصف
GMTDDeliveryVehicleReporter تلقائيًا تعديلات الموقع الجغرافي إلى
Fleet Engine. بالإضافة إلى ذلك، عندما يكون GMSNavigator في وضع التنقّل، أي عندما يتم ضبط وجهة من خلال setDestinations، يرسل الصف GMTDDeliveryVehicleReporter تلقائيًا تحديثات بشأن المسار ووقت الوصول المقدَّر.
تضبط حزمة تطوير البرامج Driver SDK المسار ليتطابق مع مسار التنقّل الحالي للسائق. لضمان تلقّي آخر المعلومات حول الموقع الجغرافي بدقة، اضبط نقطة الطريق في -setDestinations:callback: لتتطابق مع الوجهة في Fleet Engine.
يوضّح المثال التالي كيفية تفعيل تعديلات الموقع الجغرافي:
Swift
importGoogleRidesharingDriverprivateletproviderID="INSERT_YOUR_PROVIDER_ID"classSampleViewController:UIViewController,GMTDVehicleReporterListener{privateletmapView:GMSMapViewoverridefuncviewDidLoad(){// Assumes you have implemented the sample code up to this step.deliveryDriverAPI.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.deliveryDriverAPI.vehicleReporter.locationTrackingEnabled=YES;}@end
(اختياري) ضبط الفاصل الزمني للتحديث
تلقائيًا، عند ضبط locationTrackingEnabled على YES، ترسل حزمة تطوير البرامج (SDK) الخاصة ببرنامج التشغيل تحديثات الموقع الجغرافي إلى Fleet Engine كل 10 ثوانٍ. يمكنك تغيير
فترة التحديث باستخدام locationUpdateInterval إلى فترة تحديث لا تقل عن 5 ثوانٍ أو لا تزيد عن 60 ثانية. قد تؤدي التعديلات الأكثر تكرارًا إلى
بطء الطلبات وحدوث أخطاء.
تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eThe Google Maps Delivery Driver SDK enables you to set up listeners to monitor the success or failure of vehicle updates sent to Fleet Engine and your backend.\u003c/p\u003e\n"],["\u003cp\u003eYou can listen for vehicle update events such as successful updates and failures, and trigger actions within your driver app accordingly.\u003c/p\u003e\n"],["\u003cp\u003eEnable location updates in the driver app to automatically send regular location and state updates to Fleet Engine and the customer backend.\u003c/p\u003e\n"],["\u003cp\u003eYou can optionally adjust the location update interval, with a default of 10 seconds and a range between 5 and 60 seconds.\u003c/p\u003e\n"],["\u003cp\u003eEnsure the waypoint in \u003ccode\u003esetDestinations\u003c/code\u003e matches the destination in Fleet Engine for accurate location updates during navigation.\u003c/p\u003e\n"]]],[],null,["# Get the vehicle ready\n\nSet up listeners\n----------------\n\nAfter initializing the Driver SDK and creating a `GMTDDeliveryDriverAPI`\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 sends\nregular vehicle updates to Fleet Engine and the customer backend through the\n`GMTDDeliveryVehicleReporter` class. You can have the app respond to update\nevents by setting up the `GMTDVehicleReporterListener` protocol.\n\nWith `GMTDVehicleReporterListener`, you can handle the following events:\n\n- `vehicleReporter:didSucceedVehicleUpdate`\n\n Informs the Driver app that the backend services successfully received the\n vehicle location and state update.\n- `vehicleReporter:didFailVehicleUpdate:withError`\n\n Informs the listener that a vehicle update failed. As long as the driver has\n location updates enabled, the `GMTDDeliveryVehicleReporter` class continues\n to send the latest data to Fleet Engine.\n\nThe following example shows 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 deliveryDriverAPI.vehicleReporter.add(self)\n }\n\n func vehicleReporter(_ vehicleReporter: GMTDDeliveryVehicleReporter, didSucceed vehicleUpdate: GMTDVehicleUpdate) {\n // Handle update succeeded.\n }\n\n func vehicleReporter(_ vehicleReporter: GMTDDeliveryVehicleReporter, didFail vehicleUpdate: GMTDVehicleUpdate, withError error: Error) {\n // Handle update failed.\n }\n }\n\n### Objective-C\n\n SampleViewController.h\n @interface SampleViewController : UIViewController\u003cGMTDVehicleReporterListener\u003e\n @end\n\n SampleViewController.m\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 IMPLEMENTED HAVE THE SAMPLE CODE UP TO THIS STEP.\n [delivervehicleReporter addListener:self];\n }\n\n - (void)vehicleReporter:(GMTDDeliveryVehicleReporter *)vehicleReporter didSucceedVehicleUpdate:(GMTDVehicleUpdate *)vehicleUpdate {\n // Handle update succeeded.\n }\n\n - (void)vehicleReporter:(GMTDDeliveryVehicleReporter *)vehicleReporter didFailVehicleUpdate:(GMTDVehicleUpdate *)vehicleUpdate withError:(NSError *)error {\n // Handle update failed.\n }\n\n @end\n\nEnable location updates\n-----------------------\n\nTo enable location updates, in the driver app on\n`GMTDDeliveryVehicleReporter`, set `locationTrackingEnabled` to\n`YES`. Then the\n`GMTDDeliveryVehicleReporter` class automatically sends location updates to\nFleet Engine. Additionally, when the `GMSNavigator` is in navigation mode, which\nis when a destination is set through `setDestinations`, the\n`GMTDDeliveryVehicleReporter` class automatically sends route and ETA updates.\n\nThe Driver SDK sets the route to match the driver's current navigation path. To\nensure accurate location updates, set the waypoint in\n`-setDestinations:callback:` to match the 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 deliveryDriverAPI.vehicleReporter.locationTrackingEnabled = true\n }\n }\n\n### Objective-C\n\n SampleViewController.m\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 deliveryDriverAPI.vehicleReporter.locationTrackingEnabled = YES;\n }\n\n @end\n\n| **Note:** If the device has not moved since the last location update, the `GMSRoadSnappedLocationProvider` class does not send location updates continuously. For example, if a driver is waiting idle in the car. If you want to send a new location update, and have set `GMTDDeliveryVehicleReporter` as a listener after calling `startUpdatingLocation` on `GMSRoadSnappedLocationProvider`, you need to stop and start `GMSRoadSnappedLocationProvider`.\n\n### (Optional) Set the update interval\n\nBy default, when you set `locationTrackingEnabled` to `YES`, the Driver SDK\nsends location updates to Fleet Engine at a 10-second interval. You can change\nthe update interval with `locationUpdateInterval` to a minimum update interval\nof 5 seconds or a maximum of 60 seconds. More frequent updates may result in\nslower requests and errors."]]