共有プールルートの作成

このドキュメントでは、共有プール旅行を作成する方法と、 車両に割り当てることができます。フリートがセットアップ済みであることを前提としています。 自動車を作成し、運転手用アプリを使用できるようにして、 コンシューマアプリでも実行できますまた、Google Cloud で提供されている いくつか紹介します。以下の関連ガイドをご覧ください。 必要があります。

旅行の作成の基本

このセクションでは、 Fleet EnginegRPC と REST のいずれかを使用して作成リクエストを発行します。

  • CreateTrip() メソッド: gRPC または REST
  • CreateTripRequest メッセージ: gRPC のみ
で確認できます。

ルートのフィールド

Fleet Engine でルートを作成するには、次のフィールドを使用します。別の方法を使用して、 フィールドを使用して、1 つの目的地、複数の目的地、 連続してプールを行ったり、プール旅行をシェアしたりできます。マイページ ルートの作成時にオプション フィールドを指定することも、自分で ルートを更新したときに 自動的に設定されます

ルートのフィールド
名前 必須 説明
プロジェクト ID を含む文字列。この ID は、使用されている ID と同じである必要があります Fleet Engine インテグレーション全体にわたり、同じサービス アカウントで できます。
trip_id このルートを一意に識別する文字列。ルート ID の属性 特定の制限が適用されます。
trip_type 作成するルートのタイプに応じて、TripType に次の値を設定します。 <ph type="x-smartling-placeholder">
    </ph>
  • 単一のデスティネーション: SHARED または EXCLUSIVE に設定します。
  • 複数の宛先: EXCLUSIVE に設定します。
  • Back-to-back: EXCLUSIVE に設定します。
  • 共有プール: SHARED に設定します。
pickup_point ルートの出発地。
中間デスティネーション

複数の目的地を含むルートのみ: ドライバーがルート間を通る中間の目的地のリスト ピックアップとドロップオフですdropoff_point と同様に、このフィールドは 後で UpdateTrip を呼び出して設定することもできますが、マルチデスティネーション ルートには中間の目的地が含まれます。

vehicle_waypoints

共有プールのルートのみ: このフィールドでは、複数のルートのウェイポイントをインターリーブできます。 これには、割り当てられた車両の残りのウェイポイントもすべて含まれます。 このルートの乗り降り地点として設定しますこのフィールドは CreateTrip または UpdateTrip を呼び出します。また、 車両のウェイポイントを更新するには、waypoints フィールド UpdateVehicle を呼び出します。 GetTrip の呼び出しでは、サービスはこの情報を返しません。 理由があります。

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)。フリート エンジンはこのリストを使用して、すべてのルートのルートの地点を自動的に更新します 割り当てられています

たとえば、相乗りの 2 つのルート(Trip Aルート B:

  • ルート A は降車場所に向かっています。
  • そして、同じ車両に「ルート B」が追加されます。

ルート B の 1 つの UpdateTripRequest で、 vehicleId を設定し、さらに Trip.vehicle_waypoints を最適な値に 地点の順序: B 乗車持ち込みB 降車:

  • getVehicle() を呼び出すと remainingWaypoints が返される 次を含む:
    B 受け取り持ち込みB 降車
  • getTrip() または onTripRemainingWaypointsUpdated コールバック: ルート AremainingWaypoints を返します 次を含む:
    B 受け取り持ち込み
  • getTrip() または onTripRemainingWaypointsUpdated コールバック: 「ルート B」は「remainingWaypoints」を返します 次を含む:
    B ピックアップ持ち込みB 降車

次のバックエンド統合サンプルは、 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;
}

次のステップ