L'exemple suivant montre comment supprimer un trajet dans Fleet Engine.
staticfinalStringPROJECT_ID="my-rideshare-co-gcp-project";staticfinalStringTRIP_ID="trip-8241890";StringtripName="providers/"+PROJECT_ID+"/trips/"+TRIP_ID;TripServiceBlockingStubtripService=TripServiceGrpc.newBlockingStub(channel);// Delete trip request.DeleteTripRequestdeleteTripRequest=DeleteTripRequest.newBuilder().setName(tripName).build();// Error handling.try{tripService.deleteTrip(deleteTripRequest);}catch(StatusRuntimeExceptione){Statuss=e.getStatus();switch(s.getCode()){caseNOT_FOUND:// The trip doesn't exist.break;caseFAILED_PRECONDITION:// Trip is active and assigned to a vehicle.break;casePERMISSION_DENIED:break;}return;}
Gérer les erreurs
Lorsque vous supprimez un trajet, il est possible que l'erreur FAILED_PRECONDITION s'affiche. Dans ce cas, le trajet est actif et attribué à un véhicule.
Pour procéder à la suppression, appelez UpdateTrip et mettez à jour trip_status sur COMPLETE/CANCELED.
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/09/04 (UTC).
[null,null,["Dernière mise à jour le 2025/09/04 (UTC)."],[],[],null,["This document describes how to delete a trip. It assumes you\nhave set up Fleet Engine. See [Set up Fleet Engine](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet).\n\nTrip deletion basics\n\nYour system may use Fleet Engine to delete a trip in the following situations:\n\n- To perform cleanup operations while testing Fleet Engine APIs.\n- To immediately delete a Trip that is no longer required.\n\nTo delete a trip, send a request using either gRPC or REST.\n\n- `DeleteTrip()` method: [gRPC](/maps/documentation/mobility/fleet-engine/reference/trips/rpc/maps.fleetengine.v1#maps.fleetengine.v1.TripService) or [REST](/maps/documentation/mobility/fleet-engine/reference/trips/rest/v1/providers.trips/delete)\n- `DeleteTripRequest` message: [gRPC](/maps/documentation/mobility/fleet-engine/reference/trips/rpc/maps.fleetengine.v1#deletetriprequest) only\n\nUse the appropriate credentials for the service account of your project as\ndescribed in [Fleet Engine: Service account roles](/maps/documentation/mobility/fleet-engine/essentials/set-up-fleet/service-accounts).\n| **Note:** Fleet Engine automatically deletes a trip after it has been inactive for a period of time. See [Life of a trip](/maps/documentation/mobility/fleet-engine/journeys/trips#life_of_a_trip).\n\nExample: delete trip\n\nThe following example demonstrates how to delete a trip in Fleet Engine. \n\n static final String PROJECT_ID = \"my-rideshare-co-gcp-project\";\n static final String TRIP_ID = \"trip-8241890\";\n\n String tripName = \"providers/\" + PROJECT_ID + \"/trips/\" + TRIP_ID;\n\n TripServiceBlockingStub tripService = TripServiceGrpc.newBlockingStub(channel);\n\n // Delete trip request.\n DeleteTripRequest deleteTripRequest = DeleteTripRequest.newBuilder()\n .setName(tripName)\n .build();\n\n // Error handling.\n try {\n tripService.deleteTrip(deleteTripRequest);\n } catch (StatusRuntimeException e) {\n Status s = e.getStatus();\n switch (s.getCode()) {\n case NOT_FOUND: // The trip doesn't exist.\n break;\n case FAILED_PRECONDITION: // Trip is active and assigned to a vehicle.\n break;\n case PERMISSION_DENIED:\n break;\n }\n return;\n }\n\nHandle errors\n\nWhen deleting a trip, you might encounter a `FAILED_PRECONDITION` error,\nin which case the trip is active and assigned to a vehicle. \n\nTo proceed with the deletion, call `UpdateTrip` and update the `trip_status`\nto `COMPLETE`/`CANCELED`.\n\nWhat's next\n\n- [Create multi-destination trips](/maps/documentation/mobility/fleet-engine/journeys/trips/multi-destination)"]]