Skip to main content
GuidesAPI ReferenceExamples

Lane Instructions Simulated Navigation

|

In this guide you will learn how to includes lane instruction icons which appear at the bottom of the viewport whenever nearing an upcoming bifurcation, or branching, of the road.

Lane panel example #1
Lane panel example #2

A navigation is started similar to Route Navigation Example but instead of starting a real navigation a simulation is started instead. Since a simulation doesn't need current location there is no need to use PositionService to listen for valid positions nor is it needed to have location permission.

MainActivity.kt
    private fun startSimulation() = SdkCall.execute {
val waypoints = arrayListOf(
Landmark("Toamnei", 45.65060409523955, 25.616351544839894),
Landmark("Harmanului", 45.657543255739384, 25.620411332785498)
)

navigationService.startSimulation(waypoints, navigationListener, routingProgressListener)
}

The navigation listener has an onNavigationInstructionUpdated callback instance which passes NavigationInstruction objects while the navigation is ongoing. Each NavigationInstruction object contains a laneImage which is converted to a bitmap and then used to update the UI.

MainActivity.kt
    private val navigationListener: NavigationListener = NavigationListener.create(
onNavigationStarted = {
SdkCall.execute {
gemSurfaceView.mapView?.let { mapView ->
mapView.preferences?.enableCursor = false
navRoute?.let { route ->
mapView.presentRoute(route)
}

enableGPSButton()
mapView.followPosition()
}
}
},
onDestinationReached = {
SdkCall.execute { gemSurfaceView.mapView?.hideRoutes() }
},
onNavigationInstructionUpdated = { instr ->
// Fetch the bitmap for recommended lanes.
val lanes = SdkCall.execute {
instr.laneImage?.asBitmap(150, 30, activeColor = Rgba.white())
}?.second

// Show the lanes instruction.
laneImage.isVisible = lanes != null
lanes?.let { laneImage.setImageBitmap(it)}
}
)