このドキュメントでは、共有プーリングの乗車を作成し、正しいフィールドを設定して、車両に割り当てて乗車を完了する方法について説明します。このガイドは、Fleet Engine を設定済みで、車両を作成済みで、動作するドライバー アプリがあり、必要に応じて消費者向けアプリもあることを前提としています。また、オンデマンド乗車で利用できるさまざまな乗車シナリオについても理解している必要があります。関連する次のガイドをご覧ください。
- Fleet Engine を設定する
- 車両を作成する
- オンデマンド乗車の概要の乗車シナリオ
旅程作成の基本
このセクションでは、Fleet Engine で乗車を作成するために必要なリクエストの詳細について説明します。gRPC または REST を使用して作成リクエストを発行します。
Trip Fields
次のフィールドを使用して、Fleet Engine で乗車を作成します。単一または複数の目的地、連続した乗車、相乗りなど、さまざまな種類の乗車に異なるフィールドを使用できます。省略可能なフィールドは、乗車ルートの作成時に指定することも、乗車ルートの更新時に後で設定することもできます。
名前 | 必須 | 説明 |
---|---|---|
parent | ○ | プロジェクト ID を含む文字列。この ID は、フリート エンジン統合全体で同じサービス アカウント ロールで使用される 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 が乗車予定到着時刻を計算して追跡できるように、車両に割り当てる必要があります。これは、旅行の作成中に行うことも、後で旅行を更新するときに行うこともできます。
共有プールの乗車の場合、乗車の車両経由地(Trip.vehicle_waypoints
)のコレクションで、未訪問の経由地の順序を指定する必要があります。Fleet Engine はこのリストを使用して、共有プール内のすべての乗車の乗車経由地を自動的に更新します。
たとえば、Trip A と Trip B の 2 つの相乗りルートがあるとします。
- Trip A は、降車場所に向かっています。
- ルート B が同じ車両に追加されます。
Trip B の 1 つの UpdateTripRequest
で、vehicleId
を設定し、Trip.vehicle_waypoints
を最適な経由地の順序(B Pickup → A Drop-off → B Drop-off)に設定します。
getVehicle()
を呼び出すと、次の情報を含むremainingWaypoints
が返されます。
B Pickup → A Drop-off → B Drop-off。getTrip()
または Trip A のonTripRemainingWaypointsUpdated
コールバックのいずれかが、remainingWaypoints
を返します。
B Pickup → A Drop-off。- Trip B の
getTrip()
またはonTripRemainingWaypointsUpdated
コールバックのいずれかが、
(B Pickup → A Drop-off → B Drop-off)を含む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;
}