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;}
[null,null,["最后更新时间 (UTC):2025-08-31。"],[],[],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)"]]