Skip to main content
GuidesAPI ReferenceExamples

Route Simulation With Instructions

|

In this guide you will learn how to simulate navigation along a computed route rendered on an interactive map, from a departure position to a desired destination. The navigation includes on-screen text and turn arrow instructions in a panel at the top, as well as a bottom panel showing estimated time of arrival (ETA) at the destination, remaining trip time, and remaining travel distance.

Following position mode on with turn panel
Following position mode off with turn panel

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("Luxembourg", 49.61588784436375, 6.135843869736401),
Landmark("Mersch", 49.74785494642988, 6.103323786692679)
)
navigationService.startSimulation(
waypoints,
navigationListener,
routingProgressListener
)
}

The navigation listener has an onNavigationInstructionUpdated callback instance which passes NavigationInstruction objects while the navigation is ongoing.

The top navigation panel displays:

  • the turn arrow icon, instrIcon;
  • distance, instrDistance;
  • and an optional instruction, instrText.

The bottom navigation panel contains:

  • ETA - estimated time of arrival, etaText;
  • RTT - remaining travel time, rttText;
  • RTD - remaining travel distance, rtdText.
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()
}
}
topPanel.visibility = View.VISIBLE
bottomPanel.visibility = View.VISIBLE
},
onNavigationInstructionUpdated = { instr ->
var instrText = ""
var instrIcon: Bitmap? = null
var instrDistance = ""
var etaText = ""
var rttText = ""
var rtdText = ""
SdkCall.execute {
// Fetch data for the navigation top panel (instruction related info).
instrText = instr.nextStreetName ?: ""
instrIcon = instr.nextTurnImage?.asBitmap(100, 100)
instrDistance = instr.getDistanceInMeters()
// Fetch data for the navigation bottom panel (route related info).
navRoute?.apply {
etaText = getEta() // estimated time of arrival
rttText = getRtt() // remaining travel time
rtdText = getRtd() // remaining travel distance
}
}
// Update the navigation panels info.
navInstruction.text = instrText
navInstructionIcon.setImageBitmap(instrIcon)
navInstructionDistance.text = instrDistance
eta.text = etaText
rtt.text = rttText
rtd.text = rtdText
}
)

To get the ETA text:

MainActivity.kt
    private fun Route.getEta(): String
{
val etaNumber = this.getTimeDistance(true)?.totalTime ?: 0

val time = Time()
time.setLocalTime()
time.longValue += etaNumber * 1000
return String.format(Locale.getDefault(), "%d:%02d", time.hour, time.minute)
}

To get the RTT text:

MainActivity.kt
    private fun Route.getRtt(): String
{
return GemUtil.getTimeText(
this.getTimeDistance(true)?.totalTime ?: 0
).let { pair ->
pair.first + " " + pair.second
}
}

To get the RTD text:

MainActivity.kt
    private fun Route.getRtd(): String
{
return GemUtil.getDistText(
this.getTimeDistance(true)?.totalDistance ?: 0, EUnitSystem.Metric
).let { pair ->
pair.first + " " + pair.second
}
}

To get the total remaining distance use:

MainActivity.kt
    private fun NavigationInstruction.getDistanceInMeters(): String
{
return GemUtil.getDistText(
this.timeDistanceToNextTurn?.totalDistance ?: 0, EUnitSystem.Metric
).let { pair ->
pair.first + " " + pair.second
}
}