如要在 Fleet Engine 中建立隨選行程的車輛,請使用 CreateVehicle
CreateVehicleRequest
端點必須要有符合下列條件的帳戶,才能使用這個端點:
「Fleet Engine On-demand Admin」(Fleet Engine 隨選管理員) 角色。
隨選行程車輛的欄位
建立隨選行程的車輛時,您必須設定必填欄位。個人中心 應該也瞭解特定車輛欄位會對其他車輛造成什麼影響 也就是 Fleet Engine 的 核心功能相關資訊請參閱「更新車輛欄位」。
以量計價行程的必填欄位
vehicle_state
:預設為不明,但應設為「ONLINE」或 。如要瞭解如何設定車輛狀態欄位,請參閱「更新 車輛欄位。supported_trip_types
:預設為不明,但應設為 共用、獨佔或兩者皆有。請參閱隨選行程中的「行程類型」 指南。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 參考資料。