このドキュメントでは、共有プーリング トリップを作成し、正しいフィールドを設定して、車両に割り当てて実行する方法について説明します。このドキュメントは、Fleet Engine を設定し、車両を作成して、動作するドライバーアプリと、必要に応じてユーザーアプリを用意していることを前提としています。また、オンデマンド ルートで利用可能なさまざまなルートシナリオについても理解している必要があります。これについては、次の関連ガイドをご覧ください。
- Fleet Engine を設定する
- 車両を作成する
- オンデマンド トリップの概要のトリップのシナリオ
旅程の作成の基本
このセクションでは、Fleet Engine でトリップを作成するために必要なリクエストの詳細について説明します。gRPC または REST を使用して作成リクエストを発行します。
トリップ フィールド
Fleet Engine でルートを作成するには、次のフィールドを使用します。単一または複数の目的地、連続、共有プールのトリップなど、さまざまな種類のトリップに異なるフィールドを使用できます。オプション フィールドは、ルートの作成時に指定することも、ルートの更新時に設定することもできます。
| 名前 | 必須 | 説明 |
|---|---|---|
| parent | はい | プロジェクト ID を含む文字列。この ID は、Fleet Engine の統合全体で使用される ID と同じで、同じサービス アカウント ロールを持つ必要があります。 |
| trip_id | はい | このトリップを一意に識別する文字列。リファレンスに記載されているように、トリップ ID には特定の制限があります。 |
| trip_type | はい | 作成するトリップタイプに応じて、TripType を次の値に設定します。
|
| pickup_point | はい | ルートの出発地。 |
| 経由地 | はい | 複数の目的地があるトリップのみ: 乗車地と降車地の間にドライバーが立ち寄る中間目的地の一覧。 |
| vehicle_waypoints | はい | 共有プールのルートのみ: このフィールドは、複数のルートのウェイポイントのインターリーブをサポートしています。これには、割り当てられた車両の残りのすべてのウェイポイントと、このトリップの乗車場所と降車のウェイポイントが含まれます。このフィールドを設定するには、 |
| number_of_passengers | いいえ | 乗車人数。 |
| dropoff_point | いいえ | ルートの目的地。 |
| vehicle_id | いいえ | ルートに割り当てられた車両の ID。 |
例: 共有プーリング トリップを作成する
次のバックエンド統合のサンプルは、トリップを作成し、共有プーリングのトリップとして車両に割り当てる方法を示しています。
// Vehicle with VEHICLE_ID ID is already created and it is assigned Trip A.
static final String PROJECT_ID = "my-rideshare-co-gcp-project";
static final String TRIP_ID = "shared-trip-A";
static final String VEHICLE_ID = "your-vehicle-id";
static final String TRIP_A_ID = "trip-a-id";
static final String TRIP_B_ID = "trip-b-id";
TripServiceBlockingStub tripService = TripService.newBlockingStub(channel);
String parent = "providers/" + PROJECT_ID;
LatLng tripBPickup =
LatLng.newBuilder().setLatitude(-12.12314).setLongitude(88.142123).build();
LatLng tripBDropoff =
LatLng.newBuilder().setLatitude(-14.12314).setLongitude(90.142123).build();
TerminalLocation tripBPickupTerminalLocation =
TerminalLocation.newBuilder().setPoint(tripBPickup).build();
TerminalLocation tripBDropoffTerminalLocation =
TerminalLocation.newBuilder().setPoint(tripBDropoff).build();
// TripA already exists and it's assigned to a vehicle with VEHICLE_ID ID.
Trip tripB = Trip.newBuilder()
.setTripType(TripType.SHARED)
.setVehicleId(VEHICLE_ID)
.setPickupPoint(tripBPickupTerminalLocation)
.setDropoffPoint(tripBDropoffTerminalLocation)
.addAllVehicleWaypoints(
// This is where you define the arrival order for unvisited waypoints.
// If you don't specify an order, then the Fleet Engine adds Trip B's
// waypoints to the end of Trip A's.
ImmutableList.of(
// Trip B's pickup point.
TripWaypoint.newBuilder()
.setLocation(tripBPickupTerminalLocation)
.setTripId(TRIP_B_ID)
.setWaypointType(WaypointType.PICKUP_WAYPOINT_TYPE)
.build(),
// Trip A's drop-off point.
TripWaypoint.newBuilder()
.setLocation(tripA.getDropoffPoint())
.setTripId(TRIP_A_ID)
.setWaypointType(WaypointType.DROP_OFF_WAYPOINT_TYPE)
.build(),
// Trip B's drop-off point.
TripWaypoint.newBuilder()
.setLocation(tripBDropoffTerminalLocation)
.setTripId(TRIP_B_ID)
.setWaypointType(WaypointType.DROP_OFF_WAYPOINT_TYPE)
.build()))
.build();
// Create Trip request
CreateTripRequest createTripRequest = CreateTripRequest.newBuilder()
.setParent(parent)
.setTripId(TRIP_B_ID)
.setTrip(tripB)
.build();
try {
// createdTrip.remainingWaypoints will contain shared-pool waypoints.
// [tripB.pickup, tripA.dropoff, tripB.dropoff]
Trip createdTrip = tripService.createTrip(createTripRequest);
} catch (StatusRuntimeException e) {
Status s = e.getStatus();
switch (s.getCode()) {
case ALREADY_EXISTS:
break;
case PERMISSION_DENIED:
break;
}
return;
}
共有プーリング トリップを更新する
Fleet Engine で作成されたルートは、Fleet Engine がルートの ETA を計算して追跡できるように、車両に割り当てる必要があります。これは、ルートの作成中に行うことも、後でルートを更新するときに行うこともできます。
共有プールトリップの場合、トリップの車両ウェイポイントのコレクション(Trip.vehicle_waypoints)で、未訪問のウェイポイントの順序を指定する必要があります。Fleet Engine は、このリストを使用して、共有プール内のすべてのトリップのトリップ ウェイポイントを自動的に更新します。
たとえば、2 つの共有プールトリップ、トリップ A とトリップ B について考えてみましょう。
- トリップ A は降車場所に向かっています。
- その後、トリップ B が同じ車両に追加されます。
乗車 B の 1 つの UpdateTripRequest で、vehicleId を設定し、Trip.vehicle_waypoints を最適なウェイポイント順序(B 乗車 → A 降車 → B 降車)に設定します。
getVehicle()を呼び出すと、次の内容を含むremainingWaypointsが返されます。
B 乗車 → A 降車 → B 降車。getTrip()またはトリップ A のonTripRemainingWaypointsUpdatedコールバックが、B 乗車場所 → A 降車 を含むremainingWaypointsを返します。getTrip()またはルート B のonTripRemainingWaypointsUpdatedコールバックが、
B 乗車 → A 降車 → B 降車 を含むremainingWaypointsを返します。
例
次のバックエンド統合のサンプルは、2 つの共有プールルートの車両 ID とウェイポイントを使用してルートを更新する方法を示しています。
static final String PROJECT_ID = "my-rideshare-co-gcp-project";
static final String TRIP_A_ID = "share-trip-A";
static final String TRIP_B_ID = "share-trip-B";
static final String VEHICLE_ID = "Vehicle";
String tripName = "providers/" + PROJECT_ID + "/trips/" + TRIP_B_ID;
// Get Trip A and Trip B objects from either the Fleet Engine or storage.
Trip tripA = …;
Trip tripB = …;
TripServiceBlockingStub tripService = TripService.newBlockingStub(channel);
// The trip settings to update.
Trip trip = Trip.newBuilder()
.setVehicleId(VEHICLE_ID)
.addAllVehicleWaypoints(
// This is where you define the arrival order for unvisited waypoints.
// If you don't specify an order, then the Fleet Engine adds Trip B's
// waypoints to the end of Trip A's.
ImmutableList.of(
// Trip B's pickup point.
TripWaypoint.newBuilder()
.setLocation(tripB.getPickupPoint())
.setTripId(TRIP_B_ID)
.setWaypointType(WaypointType.PICKUP_WAYPOINT_TYPE)
.build(),
// Trip A's drop-off point.
TripWaypoint.newBuilder()
.setLocation(tripA.getDropoffPoint())
.setTripId(TRIP_A_ID)
.setWaypointType(WaypointType.DROP_OFF_WAYPOINT_TYPE)
.build(),
// Trip B's drop-off point.
TripWaypoint.newBuilder()
.setLocation(tripB.getDropoffPoint())
.setTripId(TRIP_B_ID)
.setWaypointType(WaypointType.DROP_OFF_WAYPOINT_TYPE)
.build()))
.build();
// The trip update request.
UpdateTripRequest updateTripRequest = UpdateTripRequest.newBuilder()
.setName(tripName)
.setTrip(trip)
.setUpdateMask(FieldMask.newBuilder()
.addPaths("vehicle_id")
.addPaths("vehicle_waypoints"))
.build();
// Error handling. If Fleet Engine has both a trip and vehicle with the IDs,
// and if the credentials validate, and if the given vehicle_waypoints list
// is valid, then the service updates the trip.
try {
Trip updatedTrip = tripService.updateTrip(updateTripRequest);
} catch (StatusRuntimeException e) {
Status s = e.getStatus();
switch (s.getCode()) {
case NOT_FOUND: // Either the trip or vehicle does not exist.
break;
case PERMISSION_DENIED:
break;
case INVALID_REQUEST: // vehicle_waypoints is invalid.
break;
}
return;
}