如需在车队引擎中创建用于随叫车辆,请将 CreateVehicle
端点与 CreateVehicleRequest
搭配使用。此端点需要具有 Fleet Engine On-demand Admin 角色的账号。
用于按需行程车辆的字段
为按需行程创建车辆时,您必须设置必填字段。您还应熟悉特定车辆字段如何影响车队引擎中的其他功能。请参阅更新车辆字段了解详情。
按需行程的必填字段
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 参考文档。