공유 풀링 여행 만들기

이 문서에서는 공유 풀링 여행을 만들고 올바른 필드를 사용하여 처리할 차량에 할당합니다. 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로 설정합니다.
  • 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)에 있습니다. 플릿 엔진은 이 목록을 사용하여 모든 이동의 경유지를 자동으로 업데이트합니다. 있습니다.

예를 들어 공유 풀 이동 경로인 AB를 생각해 보겠습니다.

  • A 이동이 반납 장소로 이동 중입니다.
  • 그러면 경로 B가 동일한 차량에 추가됩니다.

경로 BUpdateTripRequest에서 vehicleId를 설정하고 Trip.vehicle_waypoints를 최적의 중간 지점 순서인 B 픽업A 하차B 하차로 설정합니다.

  • getVehicle()을 호출하면 다음을 포함하는 remainingWaypoints가 반환됩니다.
    B 픽업A 배송B 배송
  • getTrip() 또는 경로 AonTripRemainingWaypointsUpdated 콜백은 다음을 포함하는 remainingWaypoints을 반환합니다.
    B 픽업A 드롭오프
  • getTrip() 또는 경로 BonTripRemainingWaypointsUpdated 콜백은
    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;
}

다음 단계