공유 풀링 여행 만들기

이 문서에서는 공유 풀링 여행을 만들고 올바른 필드를 사용하여 처리할 차량에 할당합니다. Fleet를 설정했다고 가정합니다. 차량을 만들었고 실제로 작동하는 운전자 앱이 있는지 소비자 앱(선택사항) 또한 Google Cloud Platform이라는 시나리오에 적용할 수 있습니다 다음 관련 가이드를 참고하세요. 다음과 같습니다.

경로 만들기 기본사항

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

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

이동 필드

다음 필드를 사용하여 Fleet Engine에서 이동을 만듭니다. 다른 여러 종류의 이동: 단일 목적지 또는 다중 목적지, 풀링 여행을 공유하는 모델입니다. 나 은 이동을 만들 때 선택적 필드를 제공할 수 있습니다. 또는 경로를 업데이트할 수 있습니다

이동 필드
이름 필수 여부 설명
parent 프로젝트 ID가 포함된 문자열입니다. 이 ID는 사용된 ID와 동일해야 합니다. 전체 Fleet Engine 통합에서 동일한 서비스 계정으로 역할을 수행합니다
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;
}

공유 풀링 여행 업데이트

차량에 할당되어야만 이동 도착예정시간을 계산하고 추적합니다 이 작업은 나중에 경로를 업데이트할 때 경로를 지정할 수 있습니다

공유 풀링 이동의 경우 방문하지 않은 경유지에 대한 순서를 지정해야 합니다. 이동 수단의 경유지 모음 (Trip.vehicle_waypoints)에 있습니다. 플릿 엔진은 이 목록을 사용하여 모든 이동의 경유지를 자동으로 업데이트합니다. 확인할 수 있습니다

예를 들어 수영장 공동 여행인 여행 A경로 B:

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

여행 B의 하나의 UpdateTripRequest에서 vehicleId를 설정하고 Trip.vehicle_waypoints도 최적으로 설정합니다. 경유지 순서: B 수령중도B 하차.

  • getVehicle()를 호출하면 remainingWaypoints이 반환됩니다. 포함:
    B 수령중도 하차B 하차.
  • getTrip() 또는 onTripRemainingWaypointsUpdated 콜백: 이동 AremainingWaypoints를 반환함 포함:
    B 수령중도.
  • getTrip() 또는 onTripRemainingWaypointsUpdated 콜백: 이동 BremainingWaypoints을(를) 반환합니다. 포함:
    B 수령A 중도B 반납.

다음 백엔드 통합 샘플은 다음을 사용하여 여행을 업데이트하는 방법을 보여줍니다. 두 개의 공유 수영장 여행에 대한 차량 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;
}

다음 단계