为按需行程创建车辆

如需在车队引擎中创建用于随叫车辆,请将 CreateVehicle 端点与 CreateVehicleRequest 搭配使用。此端点需要具有 Fleet Engine On-demand Admin 角色的账号。

用于按需行程车辆的字段

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

按需行程的必填字段

  • vehicle_state:默认为未知,但应设置为 ONLINE 或 离线。如需了解如何设置车辆状态字段,请参阅更新 车辆字段
  • supported_trip_types:默认为未知,但应设置为 “共享”和/或“独占”。如需了解详情,请参阅随叫车指南中的行程类型
  • maximum_capacity:车辆可载乘客数(不包括驾驶员,根据定义)。
  • vehicle_type:值为 AUTOTAXITRUCKTWO_WHEELER BICYCLEPEDESTRIAN。可用于过滤车辆的车辆信息 搜索。这也会影响预计到达时间和路线计算。Fleet Engine 会根据以下车辆类型群组提供与行驶方式对应的路线和行程计算结果:
    • 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 参考文档。

后续步骤