Fly To Route Instruction¶
Setup¶
First, get an API key token, see the Getting Started guide.
Download the Maps & Navigation SDK for Android archive fileDownload the FlyToRouteInstruction project
archive file or clone the project with Git
See the Configure Android Example guide.
Run the example¶
In Android Studio, from the File
menu, select Sync Project with Gradle Files
How it works¶

You can open the MainActivity.kt file to see how to fly to a specific instruction along a computed route on the map.
1// Kotlin code
2val calculateRoute =
3{
4 SdkCall.execute
5 {
6 if (!isMapReady) return@execute
7 val waypoints = arrayListOf(
8 Landmark("London", Coordinates(51.5073204, -0.1276475)),
9 Landmark("Paris", Coordinates(48.8566932, 2.3514616))
10 )
11 routingService.calculateRoute(waypoints)
12 }
13}
Coordinates are defined using a Landmark
for the departure
and another for the destination, then the routingService
instance
calculates the route using calculateRoute
.
1private fun flyToInstruction(routeInstruction: RouteInstruction)
2{
3 val animation = Animation()
4 animation.setType(EAnimation.AnimationLinear)
5 // Center the map on a specific route instruction using the provided animation.
6 mainMapView?.centerOnRouteInstruction(routeInstruction, -1, Xy(), animation)
7}
The centerOnRouteInstruction(routeInstruction, -1, Xy(), animation)
function
is used to fly to a specific instruction along the computed route.
1routingService.onCompleted = onCompleted@{ routes, reason, _ ->
2 progressBar.visibility = View.GONE
3 when (val gemError = SdkError.fromInt(reason))
4 {
5 SdkError.NoError ->
6 {
7 // No error encountered, we can handle the results.
8 SdkCall.execute
9 {
10 // Get the main route from the ones that were found.
11 val mainRoute: Route? = if (routes.size > 0)
12 {
13 routes[0]
14 } else {
15 null
16 }
17 // Get the first route instruction from the main route.
18 val routeInstruction =
19 mainRoute?.getSegments()?.get(0)?.getInstructions()?.get(0)
20
21 if (routeInstruction == null)
22 {
23 postOnMain
24 {
25 Toast.makeText(
26 this@MainActivity,
27 "No route instructions found!",
28 Toast.LENGTH_SHORT
29 )
30 .show()
31 }
32 return@execute
33 }
34 // Add the main route to the map so it can be displayed.
35 mainMapView?.preferences()?.routes()?.add(mainRoute, true)
36 flyToInstruction(routeInstruction)
37 }
38 }
mainRoute?.getSegments()?.get(0)?.getInstructions()?.get(0)
routes[0]
(the first route) from the resulting list of routes
between the departure and destination points.