این بخش نحوه آماده کردن خودرو برای سفر را نشان میدهد. قبلاز اینکه زیرینه شما بتواند خودرویی را با سفر مطابقت دهد، باید هریک از مراحل زیر را تکمیل کنید.
راهاندازی شنوندگان
پساز مقداردهی اولیه «کیت توسعه نرمافزار درایور» و ایجاد نمونه GMTDRidesharingDriverAPI
، میتوانید شنوندگان رویداد را برای نظارت بر موفقیت یا عدم موفقیت بهروزرسانیهای وسیله نقلیه ارسالی به Fleet Engine و زیرینه خود راهاندازی کنید. این شنوندگان میتوانند
کنشهایی را در برنامه راننده شما راهاندازی کنند، مثلاً اگر
ارتباط با پسای شما ناموفق باشد، به راننده اطلاع دهند.
گوش دادن به رویدادهای بهروزرسانی خودرو
وقتی راننده بهروزرسانیهای مکان را در برنامه راننده فعال میکند، «کیت توسعه نرمافزار راننده» ازطریق کلاس GMTDVehicleReporter بهروزرسانیهای منظم خودرو را به Fleet Engine و زیرینه مشتری ارسال میکند. میتوانید با راهاندازی پروتکل GMTDVehicleReporterListener،
برنامه را برای پاسخ دادن به رویدادهای بهروزرسانی تنظیم کنید.
با GMTDVehicleReporterListener، میتوانید رویدادهای زیر را مدیریت کنید:
vehicleReporter:didSucceedVehicleUpdateبه برنامه «راننده» اطلاع میدهد که سرویسهای پسزمینه با موفقیت مکان خودرو و بهروزرسانی وضعیت را دریافت کردهاند.
vehicleReporter:didFailVehicleUpdate:withErrorبه شنونده اطلاع میدهد که بهروزرسانی خودرو ناموفق بود. تا زمانی که بهروزرسانیهای مکان راننده فعال باشد، کلاس
GMTDVehicleReporterبه ارسال جدیدترین دادهها به Fleet Engine ادامه میدهد.
مثالهای زیر نشان میدهد که چگونه GMTDVehicleReporterListener را برای
رسیدگی به این رویدادها راهاندازی کنید:
Swift
import GoogleRidesharingDriver
private let providerID = "INSERT_YOUR_PROVIDER_ID"
class SampleViewController: UIViewController, GMTDVehicleReporterListener {
private let mapView: GMSMapView
override func viewDidLoad() {
// Assumes you have implemented the sample code up to this step.
ridesharingDriverAPI.vehicleReporter.add(self)
}
func vehicleReporter(_ vehicleReporter: GMTDVehicleReporter, didSucceed vehicleUpdate: GMTDVehicleUpdate) {
// Handle update succeeded.
}
func vehicleReporter(_ vehicleReporter: GMTDVehicleReporter, didFail vehicleUpdate: GMTDVehicleUpdate, withError error: Error) {
// Handle update failed.
}
}
آبجکتیو-سی
/**
* SampleViewController.h
*/
@interface SampleViewController : UIViewController<GMTDVehicleReporterListener>
@end
/**
* SampleViewController.m
*/
#import "SampleViewController.h"
#import "SampleAccessTokenProvider.h"
#import <GoogleRidesharingDriver/GoogleRidesharingDriver.h>
static NSString *const PROVIDER_ID = @"INSERT_YOUR_PROVIDER_ID";
@implementation SampleViewController {
GMSMapView *_mapView;
}
- (void)viewDidLoad {
// Assumes you have implemented the sample code up to this step.
[ridesharingDriverAPI.vehicleReporter addListener:self];
}
- (void)vehicleReporter:(GMTDVehicleReporter *)vehicleReporter didSucceedVehicleUpdate:(GMTDVehicleUpdate *)vehicleUpdate {
// Handle update succeeded.
}
- (void)vehicleReporter:(GMTDVehicleReporter *)vehicleReporter didFailVehicleUpdate:(GMTDVehicleUpdate *)vehicleUpdate withError:(NSError *)error {
// Handle update failed.
}
@end
گوش دادن به بهروزرسانیهای مکان خودرو
«کیت توسعه نرمافزار ناوبری» بهروزرسانیهای مکان را ازطریق کلاس GMSRoadSnappedLocationProvider به «کیت توسعه نرمافزار راننده» ارائه میدهد. برای دریافت این بهروزرسانیها، باید
GMTDVehicleReporter را بهعنوان شنونده تنظیم کنید.
Swift
import GoogleRidesharingDriver
private let providerID = "INSERT_YOUR_PROVIDER_ID"
class SampleViewController: UIViewController, GMTDVehicleReporterListener {
private let mapView: GMSMapView
override func viewDidLoad() {
// Assumes you have implemented the sample code up to this step.
if let roadSnappedLocationProvider = mapView.roadSnappedLocationProvider {
roadSnappedLocationProvider.add(ridesharingDriverAPI.vehicleReporter)
roadSnappedLocationProvider.startUpdatingLocation()
}
}
}
آبجکتیو-سی
/**
* SampleViewController.h
*/
@interface SampleViewController : UIViewController<GMTDVehicleReporterListener>
@end
/**
* SampleViewController.m
*/
#import "SampleViewController.h"
#import "SampleAccessTokenProvider.h"
#import <GoogleRidesharingDriver/GoogleRidesharingDriver.h>
static NSString *const PROVIDER_ID = @"INSERT_YOUR_PROVIDER_ID";
@implementation SampleViewController {
GMSMapView *_mapView;
}
- (void)viewDidLoad {
// Assumes you have implemented the sample code up to this step.
[_mapView.roadSnappedLocationProvider addListener:ridesharingDriverAPI.vehicleReporter];
[_mapView.roadSnappedLocationProvider startUpdatingLocation];
}
@end
فعال کردن بهروزرسانیهای مکان
برای فعال کردن بهروزرسانیهای مکان، locationTrackingEnabled را در true در
GMTDVehicleReporter در برنامه راننده تنظیم کنید. سپس کلاس GMTDVehicleReporter
بهطور خودکار بهروزرسانیهای مکان را به Fleet Engine ارسال میکند. پساز اینکه خدمات زیرینه مشتری و Fleet Engine خودرو را با سفر مطابقت دادند و آن را به سفر اختصاص دادند، کلاس
GMTDVehicleReporter وقتی GMSNavigator در حالت پیمایش است بهطور خودکار بهروزرسانیهای مسیر را ارسال میکند. حالت پیمایش زمانی است که مقصد ازطریق
setDestinations تنظیم شده باشد.
«کیت توسعه نرمافزار راننده» مسیر را طوری تنظیم میکند که با مسیر پیمایش فعلی راننده مطابقت داشته باشد. برای
اطمینان از بهروزرسانیهای دقیق مکان، نقطهمسیر را در setDestinations تنظیم کنید تا با
مقصد در Fleet Engine مطابقت داشته باشد.
مثال زیر نحوه فعال کردن بهروزرسانیهای مکان را نشان میدهد:
Swift
import GoogleRidesharingDriver
private let providerID = "INSERT_YOUR_PROVIDER_ID"
class SampleViewController: UIViewController, GMTDVehicleReporterListener {
private let mapView: GMSMapView
override func viewDidLoad() {
// Assumes you have implemented the sample code up to this step.
ridesharingDriverAPI.vehicleReporter.locationTrackingEnabled = true
}
}
آبجکتیو-سی
/**
* SampleViewController.m
*/
#import "SampleViewController.h"
#import "SampleAccessTokenProvider.h"
#import <GoogleRidesharingDriver/GoogleRidesharingDriver.h>
static NSString *const PROVIDER_ID = @"INSERT_YOUR_PROVIDER_ID";
@implementation SampleViewController {
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 ارسال میکند. میتوانید
فاصله بهروزرسانی را با locationUpdateInterval به حداقل فاصله بهروزرسانی
۵ ثانیه یا حداکثر ۶۰ ثانیه تغییر دهید. بهروزرسانیهای مکررتر ممکن است
منجر به درخواستهای کندتر و خطا شود.
تنظیم وضعیت خودرو روی آنلاین
پساز فعال کردن بهروزرسانیهای مکان، وضعیت خودرو را روی ONLINE تنظیم کنید تا
خودرو برای پُرسمانهای جستجو در Fleet Engine دردسترس قرار گیرد.
مثالهای زیر نحوه تنظیم وضعیت خودرو روی ONLINE را نشان میدهد. برای
جزئیات، updateVehicleState را ببینید.
Swift
import GoogleRidesharingDriver
private let providerID = "INSERT_YOUR_PROVIDER_ID"
class SampleViewController: UIViewController, GMTDVehicleReporterListener {
private let mapView: GMSMapView
override func viewDidLoad() {
// Assumes you have implemented the sample code up to this step.
ridesharingDriverAPI.vehicleReporter.update(.online)
}
}
آبجکتیو-سی
#import "SampleViewController.h"
#import "SampleAccessTokenProvider.h"
#import <GoogleRidesharingDriver/GoogleRidesharingDriver.h>
static NSString *const PROVIDER_ID = @"INSERT_YOUR_PROVIDER_ID";
@implementation SampleViewController {
GMSMapView *_mapView;
}
- (void)viewDidLoad {
// Assumes you have implemented the sample code up to this step.
[ridesharingDriverAPI.vehicleReporter
updateVehicleState:GMTDVehicleStateOnline];
}
@end