Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Vous pouvez obtenir un véhicule à partir d'un environnement de serveur à l'aide de gRPC ou de REST. Ce document fournit des exemples pour les deux.
Utiliser gRPC pour obtenir un véhicule de livraison
Java
L'exemple suivant montre comment utiliser la bibliothèque Java gRPC pour rechercher un véhicule.
staticfinalStringPROJECT_ID="my-delivery-co-gcp-project";staticfinalStringVEHICLE_ID="vehicle-8241890";DeliveryServiceBlockingStubdeliveryService=DeliveryServiceGrpc.newBlockingStub(channel);// Vehicle requestStringname="providers/"+PROJECT_ID+"/deliveryVehicles/"+VEHICLE_ID;GetDeliveryVehicleRequestgetVehicleRequest=GetDeliveryVehicleRequest.newBuilder()// No need for the header.setName(name).build();try{DeliveryVehiclevehicle=deliveryService.getDeliveryVehicle(getVehicleRequest);}catch(StatusRuntimeExceptione){Statuss=e.getStatus();switch(s.getCode()){caseNOT_FOUND:break;casePERMISSION_DENIED:break;}return;}
REST
Pour obtenir un véhicule à partir d'un environnement de serveur à l'aide de REST, effectuez un appel à GetVehicle comme suit :
GEThttps://fleetengine.googleapis.com/v1/providers/<project_id>/deliveryVehicles/<vehicleId>
# Set JWT, PROJECT_ID, and VEHICLE_ID in the local environmentcurl-H"Authorization: Bearer ${JWT}"\"https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/deliveryVehicles/${VEHICLE_ID}"
Si la recherche aboutit, le corps de la réponse contient une entité de véhicule.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/31 (UTC).
[null,null,["Dernière mise à jour le 2025/08/31 (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)"]]