使用 ListVehicles
方法尋找所有符合特定特定條件的車輛
要求選項。ListVehicles
方法會傳回車輛分頁清單
符合各車輛欄位的查詢。
依車輛屬性篩選
你也可以使用這個方法來篩選車輛屬性,系統會將其視為 AND 運算子,用於與其他欄位規格搭配使用。瞭解詳情 篩選查詢語法,請參閱篩選:AIP-160 。如要進一步瞭解如何建立車輛屬性,請參閱「交通工具」一節 屬性欄位請參閱更新車輛欄位指南。
列出車輛範例
此範例使用 ,篩選 vehicle_type
和 attributes
欄位
filter
字串,僅顯示 AUTO 類型並取得 LUXURY 的車輛
class
自訂屬性的值。
Java
static final String PROJECT_ID = "project-id";
VehicleServiceBlockingStub vehicleService = VehicleService.newBlockingStub(channel);
String parent = "providers/" + PROJECT_ID;
ListVehiclesRequest listVehiclesRequest = ListVehiclesRequest.newBuilder()
.setParent(parent)
.addTripTypes(TripType.EXCLUSIVE)
.addVehicleTypes(VehicleType.newBuilder().setCategory(VehicleType.Category.AUTO))
.setFilter("attributes.on_trip=\"false\"")
.setIncludeBackToBack(true) // Fleet Engine includes vehicles that are en route.
.build();
// Error handling
// If matches are returned and the authentication passed, the request completed
// successfully
try {
ListVehiclesResponse listVehiclesResponse =
vehicleService.listVehicles(listVehiclesRequest);
} catch (StatusRuntimeException e) {
Status s = e.getStatus();
switch (s.getCode()) {
case NOT_FOUND:
break;
case PERMISSION_DENIED:
break;
}
return;
}
REST
curl -X POST \
"https://fleetengine.googleapis.com/v1/providers/project-id/vehicles:list" \
-H "Authorization: Bearer $JWT" \
-H "Content-Type: application/json" \
--data-binary @- << EOM
{
"vehicleTypes": [{"category": "AUTO"}],
"filter": "attributes.class=\"LUXURY\"",
}
EOM