如需在 Fleet Engine 中为按需行程创建车辆,请使用 CreateVehicle
具有 CreateVehicleRequest
的端点。此端点要求使用符合以下条件的账号:
Fleet Engine On-demand Admin 角色。
按需行程车辆字段
为按需行程创建车辆时,您必须设置必填字段。您 还应该熟悉某些车场对其他 Fleet Engine 中的 Fleet Engine 功能。如需了解详情,请参阅更新车辆字段。
随叫车行程的必填字段
vehicle_state
:默认为“未知”,但应设置为“在线”或“离线”。如需了解如何设置车辆状态字段,请参阅更新 车辆字段。supported_trip_types
:默认为“未知”,但应设置为“共享”或“独占”,或同时设置为这两者。请参阅按需行程中的行程类型 获取详细信息。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 参考文档。