I’m trying to display directions when the map loads, but am running into problems. I took some of the sample code, but it’s not working for me.
override fun onDataLoaded(data: MPIData) {
val departure = mapView.venueData?.locations?.first { it.name == "My first location" }!!
val destination = mapView.venueData?.locations?.first { it.name == "My second location" }!!
mapView.getDirections(to = destination, from = departure) {
if (it != null) {
mapView.journeyManager.draw(directions = it)
}
}
}
Can you elaborate on what isn’t working? What error or behaviour are you getting? I notice that you are attempting to do this in the onDataLoaded method. At this point the MapView has downloaded the data it needs, but has not started rendering the map yet. Drawing on the map requires the app to wait for the map to be ready. Use the code you have above in the onFirstMapLoaded() method instead of onDataLoaded. If you still have issues, provide further details.