공유 풀링 여행 만들기

이 문서에서는 공유 풀링 이동을 만들고, 올바른 필드를 설정하고, 이를 차량에 할당하여 처리하는 방법을 설명합니다. Fleet Engine을 설정하고, 차량을 만들고, 작동하는 드라이버 앱과 소비자 앱(선택사항)이 있다고 가정합니다. 또한 주문형 이동에 사용할 수 있는 다양한 이동 시나리오에 익숙해야 합니다. 자세한 내용은 다음 관련 가이드를 참고하세요.

여행 항목 만들기 기본사항

이 섹션에서는 Fleet Engine에서 이동을 만드는 데 필요한 요청 세부정보를 설명합니다. gRPC 및 REST를 사용하여 생성 요청을 실행합니다.

  • CreateTrip() 메서드: gRPC 또는 REST
  • CreateTripRequest 메시지: gRPC만 해당

이동 필드

다음 필드를 사용하여 Fleet Engine에서 이동을 만듭니다. 단일 또는 다중 목적지, 연속, 공유 풀링 이동 등 다양한 유형의 이동에 서로 다른 필드를 사용할 수 있습니다. 이동을 만들 때 선택적 필드를 제공하거나 나중에 이동을 업데이트할 때 설정할 수 있습니다.

이동 필드
이름 필수 여부 설명
parent 예 프로젝트 ID가 포함된 문자열입니다. 이 ID는 동일한 서비스 계정 역할로 전체 Fleet Engine 통합에서 사용되는 ID와 동일해야 합니다.
trip_id 예 이 이동을 고유하게 식별하는 문자열입니다. 이동 ID에는 참조에 표시된 대로 특정 제한사항이 있습니다.
trip_type 예 만들려는 이동 유형에 따라 TripType을 다음 값으로 설정합니다.
  • 단일 대상: SHARED 또는 EXCLUSIVE로 설정합니다.
  • 다중 대상: EXCLUSIVE로 설정합니다.
  • 연속: EXCLUSIVE로 설정합니다.
  • 공유 풀링: SHARED로 설정합니다.
pickup_point 예 이동의 출발지입니다.
중간 목적지 예

여러 목적지 이동만 해당: 운전자가 승차와 하차 사이에 방문하는 중간 목적지 목록입니다. dropoff_point와 마찬가지로 이 필드도 나중에 UpdateTrip를 호출하여 설정할 수 있지만, 여러 목적지 이동에는 정의상 중간 목적지가 포함됩니다.

vehicle_waypoints 예

공유 풀링 이동만 해당: 이 필드는 여러 이동의 경유지를 인터리브 처리하는 것을 지원합니다. 여기에는 할당된 차량의 나머지 모든 경유지와 이 이동의 승차 및 하차 경유지가 포함됩니다. CreateTrip 또는 UpdateTrip를 호출하여 이 필드를 설정할 수 있습니다. UpdateVehicle 호출을 통해 waypoints 필드를 사용하여 차량 경유지를 업데이트할 수도 있습니다. 개인 정보 보호를 위해 서비스는 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에서 이동 ETA를 계산하고 추적할 수 있도록 차량에 할당되어야 합니다. 이 작업은 이동을 만들 때 또는 나중에 이동을 업데이트할 때 수행할 수 있습니다.

공유 풀링 이동의 경우 이동의 차량 경유지 컬렉션 (Trip.vehicle_waypoints)에서 방문하지 않은 경유지의 순서를 지정해야 합니다. Fleet Engine은 이 목록을 사용하여 공유 풀의 모든 이동에 대한 이동 경유지를 자동으로 업데이트합니다.

예를 들어 두 개의 공유 풀 이동인 이동 A와 이동 B를 생각해 보세요.

  • 이동 A가 하차 위치로 이동 중입니다.
  • 그런 다음 이동 B가 동일한 차량에 추가됩니다.

이동 B의 UpdateTripRequest 하나에서 vehicleId를 설정하고 Trip.vehicle_waypoints를 최적의 경유지 순서인 B 승차 → A 하차 → B 하차로 설정합니다.

  • getVehicle()를 호출하면 다음을 포함하는 remainingWaypoints가 반환됩니다.
    B 승차 → A 하차 → B 하차
  • getTrip() 또는 이동 A의 onTripRemainingWaypointsUpdated 콜백은 다음을 포함하는 remainingWaypoints를 반환합니다.
    B 승차 → A 하차
  • getTrip() 또는 경로 B의 onTripRemainingWaypointsUpdated 콜백은
    B 승차 → A 하차 → B 하차를 포함하는 remainingWaypoints를 반환합니다.

예

다음 백엔드 통합 샘플은 두 개의 공유 풀 이동에 대한 차량 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;
}

다음 단계