このセクションでは、車両の準備を整える方法について説明します。完了する必要があります バックエンドで車両をルートに一致させる前に、以下の各ステップを実施する必要があります。
リスナーを設定する
Driver SDK を初期化し、GMTDRidesharingDriverAPI
を作成した後
たとえば、イベント リスナーをセットアップして、イベントの成功または失敗を
車両の最新情報が
Fleet Engine とバックエンドに送信されますこれらのリスナーは
ドライバー アプリ内のアクションをトリガーできます。たとえば、
通信に失敗します。
車両の更新イベントをリッスンする
ドライバーがドライバー アプリで位置情報の更新を有効にすると、Driver SDK が
車両の更新情報を定期的に Fleet Engine と
GMTDVehicleReporter
クラスを介してバックエンドに作成されます。アプリから応答することもできます
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.
}
}
Objective-C
/**
* 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
車両の位置情報の更新をリッスンする
Navigation SDK は、SDK を使用して Driver SDK に位置情報の更新を提供します。
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()
}
}
}
Objective-C
/**
* 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
。
Driver SDK は、ドライバーの現在のナビゲーション パスと一致するようにルートを設定します。宛先
位置情報が正確に更新されるようにするには、setDestinations
で地点を一致するように設定します
宛先とされます
次の例は、位置情報の更新を有効にする方法を示しています。
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
}
}
Objective-C
/**
* 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 が
は、ルートと車両の最新情報を 10 秒間隔で Fleet Engine に送信します。Google Chat では
locationUpdateInterval
の更新間隔を最小の更新に変更する
5 秒から 60 秒まで設定できます。より頻繁なアップデートにより、
リクエストとエラーが遅くなります
車両の状態をオンラインに設定する
位置情報の更新を有効にしたら、車両の状態を 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)
}
}
Objective-C
#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