أنشِئ مركبة للرحلات المتاحة عند الطلب

لإنشاء مركبة في Fleet Engine للرحلات عند الطلب، استخدِم نقطة النهاية CreateVehicle مع CreateVehicleRequest. تتطلّب نقطة النهاية هذه حسابًا يتضمّن دور مشرف Fleet Engine عند الطلب.

حقول المركبات المخصّصة للرحلات عند الطلب

عند إنشاء مركبات للرحلات عند الطلب، يجب ضبط الحقول المطلوبة. يجب أيضًا أن تكون على دراية بكيفية تأثير حقول معيّنة للمركبات في الوظائف الأخرى في Fleet Engine. يُرجى الاطّلاع على تعديل حقول المركبات لمعرفة كيفية إجراء ذلك.

الحقول المطلوبة للرحلات عند الطلب

  • ‫vehicle_state: يتم ضبطها تلقائيًا على "غير معروف"، ولكن يجب ضبطها على "على الإنترنت" أو "بلا إنترنت". يمكنك الاطّلاع على معلومات حول ضبط حقل حالة المركبة في تعديل حقول المركبة.
  • ‫supported_trip_types: يتم ضبطه تلقائيًا على "غير معروف"، ولكن يجب ضبطه على SHARED أو EXCLUSIVE أو كليهما. لمزيد من التفاصيل، يُرجى الاطّلاع على أنواع الرحلات في دليل الرحلات عند الطلب.
  • ‫maximum_capacity: تشير هذه السمة إلى عدد الركّاب الذين يمكن للمركبة نقلهم، ولا يشمل ذلك السائق (حسب التعريف).
  • ‫vehicle_type: القيم هي AUTO أو TAXI أو TRUCK أو TWO_WHEELER أو BICYCLE أو PEDESTRIAN. يمكن استخدامها لفلترة المركبات في عمليات البحث عن المركبات. ويؤثر ذلك أيضًا في الوقت المقدَّر للوصول وحسابات المسار. يوفّر محرّك Fleet Engine المسارات وعمليات احتساب الرحلات التي تتوافق مع وضع السفر استنادًا إلى مجموعات أنواع المركبات التالية:
    • ‫AUTO أو TAXI أو TRUCK: على سبيل المثال، الطرق السريعة
    • ‫TWO_WHEELER: على سبيل المثال، لن يتم عرض المسارات التي لا يُسمح فيها بالمركبات ذات العجلتين.
    • BICYCLE: على سبيل المثال، مسارات الدراجات
    • ‫PEDESTRIAN: على سبيل المثال، الجسور والممرات المخصّصة للمشاة فقط

الحقول الأخرى

للاطّلاع على الحقول الأخرى التي يمكنك ضبطها عند إنشاء مركبة، يُرجى مراجعة تعديل حقول المركبة.

مثال على إنشاء مركبة

لإنشاء مركبة، يمكنك استخدام مكتبة Java gRPC أو REST. للحصول على قائمة كاملة باللغات المتوافقة، يُرجى الاطّلاع على مكتبات العملاء لخدمات الرحلات عند الطلب.

القيمة التي يتم عرضها من CreateVehicle هي عنصر Vehicle الذي تم إنشاؤه.

جافا

static final String PROJECT_ID = "project-id";

VehicleServiceBlockingStub vehicleService =
    VehicleService.newBlockingStub(channel);

String parent = "providers/" + PROJECT_ID;
Vehicle vehicle = Vehicle.newBuilder()
    .setVehicleState(VehicleState.OFFLINE)  // Initial state
    .addSupportedTripTypes(TripType.EXCLUSIVE)
    .setMaximumCapacity(4)
    .setVehicleType(VehicleType.newBuilder().setCategory(VehicleType.Category.AUTO))
    .addAttributes(VehicleAttribute.newBuilder()
        .setKey("on_trip").setValue("false"))  // Opaque to the Fleet Engine
    // Add .setBackToBackEnabled(true) to make this vehicle eligible for trip
    // matching while even if it is on a trip.  By default this is disabled.
    .build();

CreateVehicleRequest createVehicleRequest =
    CreateVehicleRequest.newBuilder()  // no need for the header
        .setParent(parent)
        .setVehicleId("vid-8241890")  // Vehicle ID assigned by Rideshare or Delivery Provider
        .setVehicle(vehicle)  // Initial state
        .build();

// In this case, the Vehicle is being created in the OFFLINE state and
// no initial position is being provided.  When the Driver App checks
// in with the Rideshare or Delivery Provider, the state can be set to ONLINE and
// the Driver App will update the Vehicle Location.

try {
  Vehicle createdVehicle =
      vehicleService.createVehicle(createVehicleRequest);
} catch (StatusRuntimeException e) {
  Status s = e.getStatus();
  switch (s.getCode()) {
    case ALREADY_EXISTS:
      break;
    case PERMISSION_DENIED:
      break;
  }
  return;
}
// If no Exception, Vehicle created successfully.

REST

curl -X POST \
  "https://fleetengine.googleapis.com/v1/providers/project-id/vehicles?vehicleId=vid-8241890" \
  -H "Authorization: Bearer $JWT" \
  -H "Content-Type: application/json" \
  --data-binary @- << EOM
{
    "vehicleState": "OFFLINE",
    "supportedTripTypes": ["EXCLUSIVE"],
    "maximumCapacity": 4,
    "vehicleType": {"category": "AUTO"},
    "attributes": [{"key": "on_trip", "value": "false"}]
}
EOM

يُرجى الاطّلاع على مرجع providers.vehicles.create.

الخطوات التالية