如要在車隊引擎中建立隨選行程的車輛,請使用 CreateVehicle
端點搭配 CreateVehicleRequest
。這個端點需要具備 Fleet Engine On-demand Admin 角色的帳戶。
隨選行程車輛的欄位
建立隨選行程的車輛時,您必須設定必要欄位。您也應熟悉特定車輛欄位對 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
:例如不會傳回不允許 2 輪車的路線。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 參考資料。