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

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

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

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

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

  • vehicle_state: يتم ضبط القيمة التلقائية على "غير معروف"، ولكن يجب ضبطها على ONLINE أو OFFLINE. اطّلِع على معلومات حول ضبط حقل حالة المركبة في تعديل حقول المركبة.
  • 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: على سبيل المثال، الجسور والممرات المخصّصة للمشاة فقط

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

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

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

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

Java

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.

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