เอกสารนี้จะอธิบายวิธีสร้างทริปแบบกลุ่มที่แชร์ โปรดตั้งค่า แล้วกำหนดให้กับยานพาหนะเพื่อดำเนินการตามคำสั่งซื้อ โดยจะถือว่าคุณได้ตั้งค่า Fleet แล้ว เครื่องยนต์ คุณได้สร้างยานพาหนะ มีแอปคนขับที่ใช้งานได้ และ (ไม่บังคับ) เป็นแอปสำหรับผู้บริโภค นอกจากนี้คุณควรทำความคุ้นเคยกับ สถานการณ์ที่ใช้ได้สำหรับการเดินทางแบบออนดีมานด์ ดูคำแนะนำที่เกี่ยวข้องต่อไปนี้สำหรับ ซึ่ง:
- ตั้งค่า Fleet Engine
- สร้างพาหนะ
- สถานการณ์การเดินทางในภาพรวมการเดินทางแบบออนดีมานด์
ข้อมูลเบื้องต้นเกี่ยวกับการสร้างการเดินทาง
ส่วนนี้จะอธิบายรายละเอียดคำขอที่จำเป็นสำหรับการสร้างการเดินทางใน Fleet Engine คุณส่งคำขอสร้างโดยใช้ gRPC และ REST
ช่องสำหรับการเดินทาง
ใช้ช่องต่อไปนี้เพื่อสร้างการเดินทางใน Fleet Engine คุณสามารถใช้ ช่องสำหรับการเดินทางประเภทต่างๆ ได้แก่ จุดหมายเดียวหรือหลายปลายทาง การติดต่อกลับหรือการเดินทางร่วมกัน คุณ สามารถใส่ช่องที่ไม่บังคับเมื่อสร้างการเดินทาง หรือจะตั้งค่าฟิลด์เหล่านั้น ภายหลังเมื่อคุณอัปเดตการเดินทาง
ชื่อ | จำเป็นหรือไม่ | คำอธิบาย |
---|---|---|
หลัก | ใช่ | สตริงที่มีรหัสโปรเจ็กต์ รหัสนี้ต้องเป็นรหัสเดียวกับที่ใช้ ในการผสานรวม Fleet Engine ทั้งหมดด้วยบัญชีบริการเดียวกัน บทบาทใหม่ |
trip_id | ใช่ | สตริงที่คุณสร้างซึ่งระบุการเดินทางนี้โดยไม่ซ้ำกัน รหัสการเดินทางมี ข้อจำกัดบางอย่างตามที่ระบุไว้ในข้อมูลอ้างอิง |
trip_type | ใช่ | ตั้งค่า TripType ให้เป็นค่าต่อไปนี้สำหรับประเภทการเดินทางที่กำลังสร้าง
|
pickup_point | ใช่ | จุดเริ่มต้นของการเดินทาง |
ปลายทางขั้นกลาง | ใช่ | การเดินทางที่มีหลายปลายทางเท่านั้น: รายการจุดหมายระดับกลางที่คนขับเข้าชมระหว่างทาง
การรับส่ง เช่นเดียวกับ |
vehicle_waypoints | ใช่ | การเดินทางแบบแชร์ร่วมกันเท่านั้น: ช่องนี้รองรับการสลับจุดระหว่างการเดินทางจากหลายการเดินทาง
ซึ่งประกอบด้วยจุดอ้างอิงที่เหลืออยู่ทั้งหมดสำหรับยานพาหนะที่กำหนด
เป็นจุดอ้างอิงจุดรับส่งสำหรับการเดินทางนี้ คุณสามารถตั้งค่าช่องนี้ได้
โดยโทรไปที่ |
number_of_passengers | ไม่ได้ | จำนวนผู้โดยสารในการเดินทาง |
dropoff_point | ไม่ได้ | จุดหมายของการเดินทาง |
vehicle_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 ครั้ง ได้แก่ การเดินทาง A และ การเดินทาง B:
- การเดินทาง A อยู่ระหว่างทางไปยังตำแหน่งส่ง
- จากนั้นระบบจะเพิ่มการเดินทาง B ลงในยานพาหนะเดียวกัน
ในUpdateTripRequest
1 ครั้งสำหรับการเดินทาง B
ให้ตั้งค่า vehicleId
และตั้งค่า Trip.vehicle_waypoints
เป็นค่าที่เหมาะสม
คำสั่งซื้อจุดอ้างอิง: B รับสินค้า
→ การออก →
B การออก
- การเรียกใช้
getVehicle()
จะส่งคืนremainingWaypoints
ที่มี:
B การรับสินค้า → การออก → B การออก getTrip()
หรือonTripRemainingWaypointsUpdated
Callback สำหรับ การเดินทาง A กลับมาแล้วremainingWaypoints
ที่มีสิ่งต่อไปนี้
B การรับสินค้า → การออกgetTrip()
หรือonTripRemainingWaypointsUpdated
Callback สำหรับ การเดินทาง B กลับมาแล้วremainingWaypoints
ที่มี:
ข การรับสินค้า → การเลิกใช้งาน → ข การออก
ตัวอย่าง
ตัวอย่างการผสานรวมแบ็กเอนด์ต่อไปนี้แสดงวิธีอัปเดตการเดินทางด้วย รหัสยานพาหนะและจุดอ้างอิงสำหรับการเดินทางร่วมกัน 2 เที่ยว
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;
}