Launch NavigationView
A complete turn-by-turn experience using the default NavigationLauncher
This example shows how to launch Navigation using NavigationLauncher
-
How to fetch a route using
NBNavigation.fetchRoute
with origin and destination -
How to config
NavLauncherConfig
and launch Navigation usingNavigationLauncher
with the given route
![documentation image](https://static.nextbillion.io/docs-next/docs/navigation/android/launch-navigation.jpg)
For all code examples, refer to Navigation Code Examples
activity_main.xml view source
NavigationActivity view source
Code Highlights
The example code represents a NavigationActivity class that allows users to fetch a route and start navigation using the NavigationLauncher class provided by the navigation SDK.
Code Explanation
The code example defines a layout file activity_main.xml
that contains a vertical LinearLayout
with two Button views (fetchRoute
and startNav
), a TextView
(routeGeometry
), and a ProgressBar
(progress
).
The associated Java class NavigationActivity
extends AppCompatActivity
and implements the OnClickListener
interface. In the onCreate
method, the layout elements are initialized and click listeners are set for the buttons.
When the fetchRoute
button is clicked, a network request is made using the NBNavigation
class to fetch a route between two geographic points (origin and destination). The response is received asynchronously in the onResponse
callback. If the response is successful and contains at least one route, the first route is stored in the directionsRoute
variable, and its geometry is displayed in the routeGeometry
text view. The startNav
button is enabled to allow navigation to be started.
When the startNav
button is clicked, a NavLauncherConfig
is created with the stored directionsRoute
and some configuration options. The navigation is then started using the NavigationLauncher.startNavigation
method.
Code summary
-
Fetch a route
- Using the
NBNavigation.fetchRoute
method to retrieve the directions response for the given origin and destination points. If the response is successful and it will contain at least one route
- Using the
-
Start navigation
NavLauncherConfig
object is created with the previously fetched route and additional configuration options such as location layer render mode and route simulation. TheNavigationLauncher.startNavigation
method is called to start the navigation activity with the provided configuration.