为按需行程创建车辆

如需在 Fleet Engine 中为按需行程创建车辆,请使用 CreateVehicle 具有 CreateVehicleRequest 的端点。此端点要求账号具备以下条件: Fleet Engine On-demand Admin 角色。

按需行程车辆字段

为按需行程创建车辆时,您必须设置必填字段。您 还应该熟悉某些车场对其他 Fleet Engine 中的 Fleet Engine 功能。请参阅更新车辆字段了解详情。

按需行程的必填字段

  • vehicle_state:默认为未知,但应设置为 ONLINE 或 离线。如需了解如何设置车辆状态字段,请参阅更新 车辆字段
  • supported_trip_types:默认为未知,但应设置为 “共享”和/或“独占”。请参阅按需行程中的行程类型 获取详细信息。
  • maximum_capacity:车辆可搭载的乘客人数。 (根据定义),排除了司机。
  • vehicle_type:值为 AUTOTAXITRUCKTWO-WHEELER BICYCLEPEDESTRIAN。可用于过滤车辆的车辆信息 搜索。这也会影响预计到达时间和路线计算。舰队引擎 提供 出行方式如下: <ph type="x-smartling-placeholder">
      </ph>
    • AUTOTAXITRUCK:例如高速公路。
    • 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 参考文档。

后续步骤