Получить автомобиль
Оптимизируйте свои подборки
Сохраняйте и классифицируйте контент в соответствии со своими настройками.
Вы можете получить транспортное средство из серверной среды, используя gRPC или REST. В этом документе приведены примеры для обоих вариантов.
Используйте gRPC для получения транспортного средства доставки
Ява
В следующем примере показано, как использовать библиотеку Java gRPC для поиска транспортного средства.
static final String PROJECT_ID = "my-delivery-co-gcp-project";
static final String VEHICLE_ID = "vehicle-8241890";
DeliveryServiceBlockingStub deliveryService =
DeliveryServiceGrpc.newBlockingStub(channel);
// Vehicle request
String name = "providers/" + PROJECT_ID + "/deliveryVehicles/" + VEHICLE_ID;
GetDeliveryVehicleRequest getVehicleRequest = GetDeliveryVehicleRequest.newBuilder() // No need for the header
.setName(name)
.build();
try {
DeliveryVehicle vehicle = deliveryService.getDeliveryVehicle(getVehicleRequest);
} catch (StatusRuntimeException e) {
Status s = e.getStatus();
switch (s.getCode()) {
case NOT_FOUND:
break;
case PERMISSION_DENIED:
break;
}
return;
}
ОТДЫХ
Чтобы получить транспортное средство из серверной среды с использованием REST, выполните вызов GetVehicle
следующим образом:
GET https://fleetengine.googleapis.com/v1/providers/<project_id>/deliveryVehicles/<vehicleId>
# Set JWT, PROJECT_ID, and VEHICLE_ID in the local environment
curl -H "Authorization: Bearer ${JWT}" \
"https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/deliveryVehicles/${VEHICLE_ID}"
Если поиск успешен, тело ответа содержит объект транспортного средства.
Что дальше?
Если не указано иное, контент на этой странице предоставляется по лицензии Creative Commons "С указанием авторства 4.0", а примеры кода – по лицензии Apache 2.0. Подробнее об этом написано в правилах сайта. Java – это зарегистрированный товарный знак корпорации Oracle и ее аффилированных лиц.
Последнее обновление: 2025-09-03 UTC.
[null,null,["Последнее обновление: 2025-09-03 UTC."],[[["\u003cp\u003eYou can retrieve vehicle data using either gRPC or REST methods.\u003c/p\u003e\n"],["\u003cp\u003eThis document provides code samples demonstrating how to get a vehicle using both Java gRPC and REST.\u003c/p\u003e\n"],["\u003cp\u003eBefore making vehicle requests, review the requirements in the vehicle requests section of the introduction.\u003c/p\u003e\n"],["\u003cp\u003eIf the vehicle lookup is successful, the response will contain a vehicle entity.\u003c/p\u003e\n"]]],["Before requesting a vehicle, review the requirements. Vehicles can be retrieved via gRPC or REST from a server environment. Using gRPC in Java involves creating a `GetDeliveryVehicleRequest` with the project and vehicle IDs, then using `deliveryService.getDeliveryVehicle()` to fetch it. With REST, a `GET` request to the `GetVehicle` endpoint with the project and vehicle ID is required, the response is a vehicle entity.\n"],null,["# Get a vehicle\n\n| **Note:** **Before constructing a vehicle request** , read the requirements under [Vehicle requests](/maps/documentation/mobility/fleet-engine/essentials/vehicles#vehicle_requests) in the Introduction.\n\nYou can get a vehicle either from a server environment using gRPC or REST. This\ndocument provides examples for both.\n\nUse gRPC to get a delivery vehicle\n----------------------------------\n\n### Java\n\n\nThe following example shows how to use the [Java gRPC library](/maps/documentation/mobility/fleet-engine/essentials/client-libraries-trips#java) to look up a\nvehicle. \n\n static final String PROJECT_ID = \"my-delivery-co-gcp-project\";\n static final String VEHICLE_ID = \"vehicle-8241890\";\n\n DeliveryServiceBlockingStub deliveryService =\n DeliveryServiceGrpc.newBlockingStub(channel);\n\n // Vehicle request\n String name = \"providers/\" + PROJECT_ID + \"/deliveryVehicles/\" + VEHICLE_ID;\n GetDeliveryVehicleRequest getVehicleRequest = GetDeliveryVehicleRequest.newBuilder() // No need for the header\n .setName(name)\n .build();\n\n try {\n DeliveryVehicle vehicle = deliveryService.getDeliveryVehicle(getVehicleRequest);\n } catch (StatusRuntimeException e) {\n Status s = e.getStatus();\n switch (s.getCode()) {\n case NOT_FOUND:\n break;\n case PERMISSION_DENIED:\n break;\n }\n return;\n }\n\n### REST\n\n\nTo get a vehicle from a server environment using REST, make a call to\n`GetVehicle` as follows: \n\n GET https://fleetengine.googleapis.com/v1/providers/\u003cproject_id\u003e/deliveryVehicles/\u003cvehicleId\u003e\n\n # Set JWT, PROJECT_ID, and VEHICLE_ID in the local environment\n curl -H \"Authorization: Bearer ${JWT}\" \\\n \"https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/deliveryVehicles/${VEHICLE_ID}\"\n\nIf the lookup is successful, the response body contains a vehicle entity.\n\nWhat's next\n-----------\n\n- [List delivery vehicles](/maps/documentation/mobility/fleet-engine/essentials/vehicles/on-demand-list-vehicle)"]]