LogoLogo
CMSGitHubSupportBook a demo
  • Documentation
  • Academy
  • Help Center
  • Welcome
  • SDKS & Frameworks
    • Web
      • Getting Started
        • Prerequisites
          • MapsIndoors
          • Map Engine Provider
            • Option 1: Get your Mapbox Access Token
            • Option 2: Get your Google Maps API Keys​
          • Map Engine Setup
        • Getting Started: MapsIndoors
      • Map Visualization
        • Highlight, Hover and Select
        • Remove Labels from Buildings and Venues
        • Change Building Outline
        • Managing Collisions Based on Zoom Level
        • 3D Maps
          • Managing your 3D Maps
        • Base Map Styling - Google Maps
        • Managing feature visibility for Mapbox
      • Wayfinding
        • Directions
        • Directions Service
          • Tailoring the directions to your specific needs
        • Directions Renderer
          • Customizing the Route Animation
        • Multi-stop navigation
          • Custom Icons
        • User's Location as Point of Origin
      • Search
        • Search Operations
        • Searching
        • Using External ID, Geospatial Joins
        • Utilizing MapsIndoors Web Components and Other Searches
      • Map Management
      • Data Visualization
        • Display Heatmap Overlay
      • Other guides
        • Authentication
          • Single Sign-On
            • SSO Configuration
            • SSO Authorisation
          • 2-Factor Authentication
          • Password Reset
        • Application User Roles
        • Custom Properties
        • Display Language
        • Language
        • User Positioning
          • Show User's Location aka. Blue Dot
          • Using Cisco DNA Spaces
        • Working with Events
        • Turn Off Collisions Based on Zoom Level
        • Remove Labels from Buildings and Venues for Web
        • Synchronizing data for a subset of venues
        • Custom Floor Selector
      • Display Rules in Practice
      • Offline Data
      • Managing map visibility
    • Android
      • Getting Started
        • Prerequisites
        • Create a New Project
        • Show a Map
        • Create a Search Experience
        • Getting Directions
        • Enable Live Data
        • Integrating MapsIndoors into your own App
        • Migrating from V3 to V4
          • Migrating to Mapbox V11
      • Directions
        • Directions Service
        • Directions Renderer
          • User's Location as Point of Origin
        • Wayfinding Instructions
          • See Route Element Details
        • Using multi-stop navigation
      • Searching
        • Searching on a Map
        • Creating a Search Experience
      • Switching Solutions
      • Caching & Offline Data
      • Display Language
      • Displaying Objects
        • Application User Roles
        • Getting a Polygon from a Location
        • Location Clustering
        • Location Data Sources
        • Location Details
        • Turn Off Collisions Based on Zoom Level
        • Enabling and Disabling features on the map
      • Change Building Outline Color
      • Event Logging
      • Configuring a menu with AppConfig
      • Display Heatmap Overlay
      • Custom Properties
      • Custom Floor Selector
      • External IDs
      • User Positioning
        • Show User's Location aka. Blue Dot
        • Using Cisco DNA Spaces
        • Using Google Fused Location Provider
        • Using Indoor Atlas
      • Authentication
        • Single Sign-On
          • SSO Configuration
          • SSO Authorisation
        • 2-Factor Authentication
        • Password Reset
      • Display Rules in Practice
        • Label styling through Display Rules
      • Highlight and Select
    • iOS
      • Getting Started
        • Prerequisites
        • Set Up Your Environment
        • Display a Map
        • Search
        • Getting Directions
        • Migrating from v3 to v4
      • Directions
        • Directions Renderer
          • User's Location as Point of Origin
        • Wayfinding Instructions
          • See Route Element Details
        • Directions Service
        • Using multi-stop navigation
      • Searching
        • Searching on a Map
        • Creating a Search Experience
      • Caching & Offline Data
      • Displaying Objects
        • Application User Roles
        • Getting a Polygon from a Location
        • Location Details
        • Turn Off Collisions Based on Zoom Level
        • Enabling and Disabling features on the map
      • Custom Floor Selector
      • Change Building Outline Color
      • Custom Map Padding
      • Custom Properties
      • Display Rules in Practice
        • Label styling through Display Rules
      • Switching Solutions
      • Show User's Location aka. Blue Dot
        • Using Indoor Atlas
        • Using Cisco DNA Spaces
      • Highlight and Select
      • Display Language
    • React Native
      • Getting Started
        • Prerequisites
        • Project Setup
        • Displaying a Map
        • Creating a Search Experience
        • Getting Directions
        • Enabling Live Data
      • Showing Blue Dot
    • Flutter
      • Getting Started
        • Prerequisites
        • Create a New Project
        • Show a Map
        • Create a Search Experience
        • Getting Directions
      • Migration Guide
    • Integration API
      • Integration API Access
        • Access with Swagger
        • Access with Postman
        • Access with Python
        • Client credentials flow
      • Data Description
      • Reverse Geocoding
      • Route Access
      • OpenAPI Specification
    • Built-In Map Edits
      • Getting started
      • Authentication
      • Release notes
      • Reference docs
  • Products
    • Product Overview
    • CMS
      • Interface Overview
      • Display Rules
      • Media Library
        • 2D Models and Icons
        • 3D Models
      • Editing Data
      • Solution Settings
      • Settings
      • Data Concepts
      • User Roles
      • Route Network
        • Barrier Route Element
        • Door Route Element
      • Additional Location Details
    • Map Template
      • Getting Started
        • Web Component
        • React Component
      • Configuration
        • Query Parameters
      • Customization
      • Deploying Map Template to a cloud storage provider
      • 2D/3D Visibility Switch
      • External customization of the Map Template
      • Location Details configuration
      • Kiosk
        • QR code configuration
  • Other
    • Design
      • Standard MapsIndoors Map Style
      • Using a Custom Mapbox MapStyle
    • Changelog
      • Web SDK
        • V4
        • V3
      • Android SDK
        • V4
        • V3
      • iOS SDK
        • V4
        • V3
      • React Native SDK
      • Flutter SDK
      • MI Components
      • Map Template
    • Glossary
  • Legacy Docs
    • Android SDK V3
      • Getting Started
        • Prerequisites
        • Create a New Project
        • Show a Map
        • Create a Search Experience
        • Getting Directions
        • Enable Live Data
        • Integrating MapsIndoors into your own App
    • iOS SDK V3
      • Getting Started
        • Prerequisites
        • Set Up Your Environment
        • Display a Map
        • Search
        • Directions
        • Live Data
        • Integrating MapsIndoors into your own App
      • Inspect Route Element for iOS v3
      • Using Cisco DNA Spaces
      • Using Indoor Atlas
      • Switching Solutions
      • Show User's Location aka. Blue Dot
      • Application User Roles
      • Getting a Polygon from a Location
      • Location Details
  • MapsIndoors SDK Firewall
  • Google Analytics & Logging
  • Reference Docs
    • Web SDK
    • Android SDK
    • iOS SDK
    • React Native SDK
    • Flutter SDK
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. SDKS & Frameworks
  2. Android
  3. Directions

Directions Renderer

Android v4

Last updated 8 months ago

Was this helpful?

When getting the resulting Route from a , you may want to display this Route on a map. To perform this task the MPDirectionsRenderer can be used.

This example shows how to setup a query for a route and display the result on a Google Map using the MPDirectionsRenderer:

void getRoute() {
    MPDirectionsService directionsService = new MPDirectionsService(this);
    MPDirectionsRenderer directionsRenderer = new MPDirectionsRenderer(mMapControl);
    MPPoint origin = new MPPoint(57.057917, 9.950361, 0.0);
    MPPoint destination = new MPPoint(57.058038, 9.950509, 0.0);
    directionsService.setRouteResultListener((route, error) -> {
        if (route != null) {
            directionsRenderer.setRoute(route);
        }
    });
    directionsService.query(origin, destination);
}

Controlling the Visible Segments on the Directions Renderer

As previously mentioned, the route object is seperated into objects of MPRouteLeg. Each leg is again separated into objects of MPRouteStep.

Unless the Route only contains one Leg, the Directions Renderer does not allow the full Route to be rendered all at once. Therefore, if a Leg contains multiple Steps, they will all be shown on the map at the same time, but once the Leg is changed, the previous Steps are not visible anymore.

A specific segment of the route can be rendered by setting the legIndex on the MPDirectionsRenderer.

void setLegIndex(int position) {
    mpDirectionsRenderer.selectLegIndex(position);
}

The length of the legs array from getLegs on the MPRoute object determines the possible values of routeLegIndex (0 ..< length).

Directions Labels refer to the labels shown at the end of the rendered route segment path, that may provide contextual information, or show instructions for a required user action at that point. The labels are created as simple Marker instances that are rendered as markers on the map. A user is able to long press these, and an event will be forwarded to the listener OnLegSelectedListener in MPDirectionsRenderer. This can be used to change the Leg to the next Leg in line on the Route.

void getRoute() {
    MPDirectionsService directionsService = new MPDirectionsService(this);
    MPDirectionsRenderer directionsRenderer = new MPDirectionsRenderer(mMapControl);
    MPPoint origin = new MPPoint(57.057917, 9.950361, 0.0);
    MPPoint destination = new MPPoint(57.058038, 9.950509, 0.0);
    directionsService.setRouteResultListener((route, error) -> {
        if (route != null) {
            directionsRenderer.setRoute(route);
        }
    });
    directionsRenderer.setOnLegSelectedListener(i -> {
        directionsRenderer.selectLegIndex(i);
    });
    directionsService.query(origin, destination);
}

MPDirectionsRenderer also has convenience methods to change the active leg to previous and next Leg.

void nextLeg() {
    mpDirectionsRenderer.nextLeg();
}
void previousLeg() {
    mpDirectionsRenderer.previousLeg();
}

It is possible to show contextual information on the end points of the rendered path of a route segment by configuring the directions renderer to look for nearby Locations or POIs.

This is done by creating an appropriate MPContextualInfoSettings object and passing that to the Directions Renderer. If it is not set or is null, no contextual information will be shown.

The MPContextualInfoSetting can be applied on MPDirectionsRenderer by calling useContentOfNearbyLocations(MPContextualInfoSettings). Like this:

//Sets the contextual info to be of locations that has the type "entries" and searches within a max distance of 30 meters from the end point of the current route segment
mpDirectionsRenderer.useContentOfNearbyLocations(new MPContextualInfoSettings.Builder()
        .setTypes(Collections.singletonList("entries"))
        .setMaxDistance(30.0)
        .build());

The defaults of the ContextualInfoSettings builder are maxDistance at 5 meters and the ContextualInfoScope as icon and name. No Types or Categories are set as default. Not applying any Types or Categories will make it search through all Locations to use as contextual information.

This example shows how to setup a query for a route and display the result on a Google Map using the MPDirectionsRenderer:

fun getRoute() {
    val directionsService = MPDirectionsService(this)
    val directionsRenderer = MPDirectionsRenderer(mMapControl)
    val origin = MPPoint(57.057917, 9.950361, 0.0)
    val destination = MPPoint(57.058038, 9.950509, 0.0)
    directionsService.setRouteResultListener { route, error ->
        route?.let { mpRoute ->
            directionsRenderer.setRoute(mpRoute)
        }
    }
    directionsService.query(origin, destination)
}

As previously mentioned, the route object is seperated into objects of MPRouteLeg. Each leg is again separated into objects of MPRouteStep.

Unless the Route only contains one Leg, the Directions Renderer does not allow the full Route to be rendered all at once. Therefore, if a Leg contains multiple Steps, they will all be shown on the map at the same time, but once the Leg is changed, the previous Steps are not visible anymore.

A specific segment of the route can be rendered by setting the legIndex on the MPDirectionsRenderer.

fun setRouteLegIndex(position: Int) {
    mpDirectionsRenderer?.selectLegIndex(position)
}

The length of the legs array from getLegs on the MPRoute object determines the possible values of routeLegIndex (0 ..< length).

Directions Labels refer to the labels shown at the end of the rendered route segment path, that may provide contextual information, or show instructions for a required user action at that point. The labels are created as simple Marker instances that are rendered as markers on the map. A user is able to long press these, and an event will be forwarded to the listener OnLegSelectedListener in MPDirectionsRenderer. This can be used to change the Leg to the next Leg in line on the Route.

fun getRoute() {
    val directionsService = MPDirectionsService(this)
    val directionsRenderer = MPDirectionsRenderer(mMapControl)
    val origin = MPPoint(57.057917, 9.950361, 0.0)
    val destination = MPPoint(57.058038, 9.950509, 0.0)
    directionsService.setRouteResultListener { route, error ->
        route?.let { mpRoute ->
            directionsRenderer.setRoute(mpRoute)
        }
    }
    directionsRenderer.setOnLegSelectedListener {
        mpDirectionsRenderer?.selectLegIndex(it)
    }
    directionsService.query(origin, destination)
}

MPDirectionsRenderer also has convenience methods to change the active leg to previous and next Leg.

fun nextLeg() {
    mpDirectionsRenderer?.nextLeg()
}
fun previousLeg() {
    mpDirectionsRenderer?.previousLeg()
}

It is possible to show contextual information on the end points of the rendered path of a route segment by configuring the directions renderer to look for nearby Locations or POIs.

This is done by creating an appropriate MPContextualInfoSettings object and passing that to the Directions Renderer. If it is not set or is null, no contextual information will be shown.

The MPContextualInfoSetting can be applied on MPDirectionsRenderer by calling useContentOfNearbyLocations(MPContextualInfoSettings). Like this:

//Sets the contextual info to be of locations that has the type "entries" and searches within a max distance of 30 meters from the end point of the current route segment
mpDirectionsRenderer?.useContentOfNearbyLocations(MPContextualInfoSettings.Builder()
            .setTypes(Collections.singletonList("entries"))
            .setMaxDistance(30.0)
            .build())

The defaults of the ContextualInfoSettings builder are maxDistance at 5 meters and the ContextualInfoScope as icon and name. No Types or Categories are set as default. Not applying any Types or Categories will make it search through all Locations to use as contextual information.

Reacting to Label Tapping

Show Content of Nearby Locations

When getting the resulting Route from a , you may want to display this Route on a map. To perform this task the MPDirectionsRenderer can be used.

Controlling the Visible Segments on the Directions Renderer

Reacting to Label Tapping

Show Content of Nearby Locations

Directions Service
​
​
​
Directions Service
​
​
​