차량 준비

이 섹션에서는 이동을 위해 차량을 준비하는 방법을 보여줍니다. 다음을 완료해야 합니다. 다음 각 단계를 완료해야 백엔드에서 차량을 이동과 일치시킬 수 있습니다.

리스너 설정

드라이버 SDK를 초기화하고 GMTDRidesharingDriverAPI를 만든 후 인스턴스의 성공 또는 실패를 모니터링하도록 이벤트 리스너를 설정할 수 있습니다. 차량 업데이트가 Fleet Engine과 백엔드로 전송됩니다. 이러한 리스너는 작업을 실행할 수 있습니다. 통신할 수 없습니다

차량 업데이트 이벤트 수신 대기

운전자가 드라이버 앱에서 위치 업데이트를 사용 설정하면 Driver SDK는 Fleet Engine 및 고객에게 정기적인 차량 업데이트 전송 GMTDVehicleReporter 클래스를 통해 백엔드로 전달됩니다. 앱이 응답하도록 할 수 있습니다. GMTDVehicleReporterListener 프로토콜을 설정하여 이벤트를 업데이트합니다.

GMTDVehicleReporterListener를 사용하면 다음 이벤트를 처리할 수 있습니다.

다음 예는 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는 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

업데이트 간격 설정

기본적으로 locationTrackingEnabledtrue로 설정하면 Driver SDK가 10초 간격으로 이동 및 차량 업데이트를 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)
  }
}

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

다음 단계

경로 세부정보 설정