如需在 Fleet Engine 中为按需行程创建车辆,请使用 CreateVehicle
端点和 CreateVehicleRequest
。此端点需要具有 Fleet Engine On-demand Admin 角色的账号。
按需行程车辆的字段
为按需行程创建车辆时,您必须设置必需字段。您还应熟悉某些车辆字段如何影响 Fleet Engine 中的其他功能。如需了解相关信息,请参阅更新车辆字段。
按需行程的必填字段
vehicle_state
:默认值为 unknown,但应设置为 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 参考文档。