使用 ListVehicles
方法找出符合特定要求選項的所有車輛。ListVehicles
方法會傳回專案中的車輛分頁清單,該清單會在車輛欄位中比對查詢。
依車輛屬性篩選
您也可以使用這個方法篩選車輛屬性,當與其他欄位規格搭配使用時,會做為 AND 運算子。如需篩選器查詢語法的詳細資訊,請參閱「篩選:AIP-160」一文中的範例。如要進一步瞭解如何建立車輛屬性,請參閱「交通工具」一節 屬性欄位請參閱更新車輛欄位指南。
列出車輛範例
這個範例會使用 filter
字串篩選 vehicle_type
和 attributes
欄位,只顯示 AUTO 類型的車輛,並取得 class
自訂屬性的 LUXURY 值。
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