如要在 Fleet Engine 中建立車輛,以供隨選行程使用,請搭配 CreateVehicleRequest 使用 CreateVehicle 端點。如要使用這個端點,帳戶必須具備 Fleet Engine On-demand 管理員角色。
隨選行程車輛的欄位
為隨選行程建立車輛時,必須設定必填欄位。此外,您也應熟悉特定車輛欄位對 Fleet Engine 其他功能的影響。如要瞭解如何更新車輛欄位,請參閱這篇文章。
按需旅行的必填字段
vehicle_state:預設為 unknown,但應設為 ONLINE 或 OFFLINE。如要瞭解如何設定車輛狀態欄位,請參閱「更新車輛欄位」。supported_trip_types: 預設為未知,但應設定為 SHARED、EXCLUSIVE 或兩者。有關詳細信息,請參閱 按需旅行 指南中的 旅行類型。maximum_capacity:車輛可搭載的乘客人數,不包括駕駛人 (根據定義)。vehicle_type:值為AUTO、TAXI、TRUCK、TWO_WHEELER、BICYCLE或PEDESTRIAN。可用於篩選車輛搜尋結果。這也會影響預計到達時間和路線計算。車隊引擎根據以下車輛類型組提供與出行方式相對應的路線和行程計算: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 參考資料。