يصف هذا المستند كيفية إنشاء رحلة تجميع مشتركة، وتعيين الحقول وتعيينها لمركبة لتنفيذها. من المفترض أنك أعددت Fleet محرّك Google، وقمت بإنشاء مركبات، والحصول على تطبيق سائق قيد التشغيل، اختياريًا، تطبيق المستهلك. ينبغي أن تكون على دراية بالرحلات المختلفة المتاحة للرحلات عند الطلب. اطّلِع على الأدلة التالية ذات الصلة حول الذي:
- إعداد 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
). الأسطول
يستخدم محرّك البحث هذه القائمة لتعديل نقاط طريق الرحلة تلقائيًا لجميع الرحلات.
في حوض السباحة المشترك.
على سبيل المثال، فكّر في رحلتين مشتركتين في حوض السباحة، وهما الرحلة أ الرحلة ب:
- الرحلة أ في طريقها إلى موقع التسليم.
- تتم بعد ذلك إضافة الرحلة "ب" إلى المركبة نفسها.
في UpdateTripRequest
واحدة للرحلة ب،
وضبطت vehicleId
، وأيضًا ضبط Trip.vehicle_waypoints
على القيمة الأمثل
ترتيب نقاط الطريق: B استلام الطلب
→ الانسحاب →
ب الانسحاب:
- يؤدي الاتصال بالرقم
getVehicle()
إلى إرجاعremainingWaypoints
. التي تحتوي على:
ب استلام الطلب → الانسحاب → ب الانسحاب: - إما
getTrip()
أو معاودة الاتصالonTripRemainingWaypointsUpdated
لـ الرحلة أ تُرجعremainingWaypoints
التي تحتوي على:
ب استلام الطلب → الانسحاب: - إما
getTrip()
أو معاودة الاتصالonTripRemainingWaypointsUpdated
لـ إرجاع الرحلة بremainingWaypoints
التي تحتوي على:
ب استلام الطلب → الانسحاب → ب الانسحاب:
مثال
يوضح نموذج دمج الخلفية التالي كيفية تحديث رحلة باستخدام معرف المركبة ونقاط الطريق لرحلتين مشتركتين في حمام سباحة.
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;
}