privatevoidnavigateToLocation(LatLnglocationLatLng,RoutingOptionsroutingOptions){Waypointdestination=Waypoint.newBuilder().setLocation(locationLatLng).build();// Create a future to await the result of the asynchronous navigator task.ListenableResultFuture<Navigator.RouteStatus>pendingRoute=mNavigator.setDestination(destination,travelMode);// Define the action to perform when the SDK has determined the route.pendingRoute.setOnResultListener(newListenableResultFuture.OnResultListener<Navigator.RouteStatus>(){@OverridepublicvoidonResult(Navigator.RouteStatuscode){switch(code){caseOK:// Hide the toolbar to maximize the navigation UI.if(getActionBar()!=null){getActionBar().hide();}// Enable voice audio guidance (through the device speaker).mNavigator.setAudioGuidance(Navigator.AudioGuidance.VOICE_ALERTS_AND_GUIDANCE);// Simulate vehicle progress along the route for demo/debug builds.if(BuildConfig.DEBUG){mNavigator.getSimulator().simulateLocationsAlongExistingRoute(newSimulationOptions().speedMultiplier(5));}// Start turn-by-turn guidance along the current route.mNavigator.startGuidance();break;// Handle error conditions returned by the navigator.caseNO_ROUTE_FOUND:displayMessage("Error starting navigation: No route found.");break;caseNETWORK_ERROR:displayMessage("Error starting navigation: Network error.");break;caseROUTE_CANCELED:displayMessage("Error starting navigation: Route canceled.");break;default:displayMessage("Error starting navigation: "+String.valueOf(code));}}});}
Kotlin
privatefunnavigateToLocation(locationLatLng:LatLng,travelMode:RoutingOptions){valdestination=Waypoint.newBuilder().setLocation(locationLatLng).build()// Create a future to await the result of the asynchronous navigator task.valpendingRoute=mNavigator.setDestination(destination,travelMode)// Define the action to perform when the SDK has determined the route.pendingRoute.setOnResultListener(object:ListenableResultFuture.OnResultListener<Navigator.RouteStatus>(){overridefunonResult(code:Navigator.RouteStatus){when(code){Navigator.RouteStatus.OK->{// Hide the toolbar to maximize the navigation UI.getActionBar()?.hide()// Enable voice audio guidance (through the device speaker).mNavigator.setAudioGuidance(Navigator.AudioGuidance.VOICE_ALERTS_AND_GUIDANCE)// Simulate vehicle progress along the route for demo/debug builds.if(BuildConfig.DEBUG){mNavigator.getSimulator().simulateLocationsAlongExistingRoute(SimulationOptions().speedMultiplier(5))}// Start turn-by-turn guidance along the current route.mNavigator.startGuidance()}Navigator.RouteStatus.NO_ROUTE_FOUND->{displayMessage("Error starting navigation: No route found.")}Navigator.RouteStatus.NETWORK_ERROR->{displayMessage("Error starting navigation: Network error.")}Navigator.RouteStatus.ROUTE_CANCELED->{displayMessage("Error starting navigation: Route canceled.")}else->{displayMessage("Error starting navigation: ${code.name}")}}}})}
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThis guide explains how to set a vehicle's destination in your driver app after a trip is matched using Fleet Engine and the Driver SDK.\u003c/p\u003e\n"],["\u003cp\u003eYou need to retrieve the destination waypoints from Fleet Engine's \u003ccode\u003eGetTrip()\u003c/code\u003e, \u003ccode\u003eUpdateTrip()\u003c/code\u003e, or \u003ccode\u003eGetVehicle()\u003c/code\u003e methods.\u003c/p\u003e\n"],["\u003cp\u003eUse the Navigation SDK's \u003ccode\u003esetDestination()\u003c/code\u003e method, ensuring the coordinates match the trip's waypoint for proper consumer app rendering.\u003c/p\u003e\n"],["\u003cp\u003eCode samples in Java and Kotlin demonstrate how to implement destination setting and initiate turn-by-turn navigation in the driver app.\u003c/p\u003e\n"]]],["After pairing a consumer with a driver, configure the trip's destination in the driver app. First, retrieve the vehicle's destination from Fleet Engine's waypoints collection using `GetTrip()`, `UpdateTrip()`, or `GetVehicle()`. Then, set the destination by calling the Navigation SDK's `setDestination()` method. Ensure the provided latitude/longitude coordinates match the trip's waypoint. Finally, enable voice guidance, optionally simulate vehicle progress, and initiate turn-by-turn guidance with `startGuidance()`. Handle any errors as required.\n"],null,["This section documents how to set the vehicle's destination after your server\nmatches a trip to a vehicle.\n\nBefore you begin\n\nThis section requires you to have completed the following:\n\n- [Initialize the Driver SDK](/maps/documentation/mobility/driver-sdk/on-demand/android/initialize-sdk)\n- [Get the vehicle ready](/maps/documentation/mobility/driver-sdk/on-demand/android/vehicle-ready)\n- [Create a trip in Fleet Engine](/maps/documentation/mobility/fleet-engine/journeys/trips/create-trip)\n\nSet the destination in the driver app\n\nAfter you have paired a consumer with a driver, you must configure the trip's\ndestination in the driver app by performing the following steps:\n\n1. Retrieve the vehicle's destination from its waypoints collection in Fleet\n Engine, which is returned by `GetTrip()`, `UpdateTrip()` and `GetVehicle()`.\n\n2. Set the destination by calling the Navigation SDK for Android method\n [`setDestination()`](/maps/documentation/navigation/android-sdk/reference/com/google/android/libraries/navigation/Navigator#public-abstract-listenableresultfuturenavigator.routestatus-setdestination-waypoint-destination).\n\n | **Note:** For the consumer app to properly render the trip, make sure the geographic latitude/longitude coordinates supplied to `setDestination()` match those in the trip's waypoint. For more information, see the tutorials [Route to a Single Destination](/maps/documentation/navigation/android-sdk/route) and [Route to Multiple Destinations](/maps/documentation/navigation/android-sdk/multi-destination).\n\nThe following examples show how to set the destination in the driver\napp. \n\nJava \n\n private void navigateToLocation(LatLng locationLatLng, RoutingOptions routingOptions) {\n Waypoint destination = Waypoint.newBuilder().setLocation(locationLatLng).build();\n\n // Create a future to await the result of the asynchronous navigator task.\n ListenableResultFuture\u003cNavigator.RouteStatus\u003e pendingRoute =\n mNavigator.setDestination(destination, travelMode);\n\n // Define the action to perform when the SDK has determined the route.\n pendingRoute.setOnResultListener(\n new ListenableResultFuture.OnResultListener\u003cNavigator.RouteStatus\u003e() {\n @Override\n public void onResult(Navigator.RouteStatus code) {\n switch (code) {\n case OK:\n // Hide the toolbar to maximize the navigation UI.\n if (getActionBar() != null) {\n getActionBar().hide();\n }\n\n // Enable voice audio guidance (through the device speaker).\n mNavigator.setAudioGuidance(\n Navigator.AudioGuidance.VOICE_ALERTS_AND_GUIDANCE);\n\n // Simulate vehicle progress along the route for demo/debug builds.\n if (BuildConfig.DEBUG) {\n mNavigator.getSimulator().simulateLocationsAlongExistingRoute(\n new SimulationOptions().speedMultiplier(5));\n }\n\n // Start turn-by-turn guidance along the current route.\n mNavigator.startGuidance();\n break;\n // Handle error conditions returned by the navigator.\n case NO_ROUTE_FOUND:\n displayMessage(\"Error starting navigation: No route found.\");\n break;\n case NETWORK_ERROR:\n displayMessage(\"Error starting navigation: Network error.\");\n break;\n case ROUTE_CANCELED:\n displayMessage(\"Error starting navigation: Route canceled.\");\n break;\n default:\n displayMessage(\"Error starting navigation: \"\n + String.valueOf(code));\n }\n }\n });\n }\n\nKotlin \n\n private fun navigateToLocation(locationLatLng: LatLng, travelMode: RoutingOptions) {\n val destination = Waypoint.newBuilder().setLocation(locationLatLng).build()\n\n // Create a future to await the result of the asynchronous navigator task.\n val pendingRoute = mNavigator.setDestination(destination, travelMode)\n\n // Define the action to perform when the SDK has determined the route.\n pendingRoute.setOnResultListener(\n object : ListenableResultFuture.OnResultListener\u003cNavigator.RouteStatus\u003e() {\n override fun onResult(code: Navigator.RouteStatus) {\n when (code) {\n Navigator.RouteStatus.OK -\u003e {\n // Hide the toolbar to maximize the navigation UI.\n getActionBar()?.hide()\n\n // Enable voice audio guidance (through the device speaker).\n mNavigator.setAudioGuidance(Navigator.AudioGuidance.VOICE_ALERTS_AND_GUIDANCE)\n\n // Simulate vehicle progress along the route for demo/debug builds.\n if (BuildConfig.DEBUG) {\n mNavigator\n .getSimulator()\n .simulateLocationsAlongExistingRoute(SimulationOptions().speedMultiplier(5))\n }\n\n // Start turn-by-turn guidance along the current route.\n mNavigator.startGuidance()\n }\n Navigator.RouteStatus.NO_ROUTE_FOUND -\u003e {\n displayMessage(\"Error starting navigation: No route found.\")\n }\n Navigator.RouteStatus.NETWORK_ERROR -\u003e {\n displayMessage(\"Error starting navigation: Network error.\")\n }\n Navigator.RouteStatus.ROUTE_CANCELED -\u003e {\n displayMessage(\"Error starting navigation: Route canceled.\")\n }\n else -\u003e {\n displayMessage(\"Error starting navigation: ${code.name}\")\n }\n }\n }\n }\n )\n }"]]