如要在 Fleet Engine 中建立車輛,以供隨選行程使用,請搭配 CreateVehicleRequest
使用 CreateVehicle
端點。如要使用這個端點,帳戶必須具備 Fleet Engine On-demand 管理員角色。
隨選行程車輛的欄位
為隨選行程建立車輛時,必須設定必要欄位。此外,您也應熟悉特定車輛欄位對 Fleet Engine 其他功能的影響。如要瞭解如何更新車輛欄位,請參閱這篇文章。
隨選行程的必填欄位
vehicle_state
:預設為 unknown,但應設為 ONLINE 或 OFFLINE。如要瞭解如何設定車輛狀態欄位,請參閱「更新車輛欄位」。supported_trip_types
:預設為 unknown,但應設為 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 參考資料。