> For the complete documentation index, see [llms.txt](https://docs.mapsindoors.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mapsindoors.com/sdks-and-frameworks/android/directions/using-multi-stop-navigation.md).

# Using multi-stop navigation

Multi-stop navigation has been introduced with the release of 4.8.0. This allows users to be navigated to multiple stops within a single route.

### Querying a multi-stop route

To query a multistop route a new overload `MPDirectionsService.query` has been introduced `MPDirectionsService.query(from: MPPoint, to: MPPoint, stops: List<MPPoint>?, optimize: Boolean)`.

<pre class="language-kotlin"><code class="lang-kotlin">private var directionsService: MPDirectionsService = MPDirectionsService()

//Example of querying an optimized route with multiple stops
fun getRoute() {
    if (directionsService != null) {
        directionsService = MPDirectionsService()
<strong>    }
</strong><strong>    //Setting listener to receive the queried route
</strong><strong>    directionsService.setRouteResultListener { route, error ->
</strong><strong>        if (error == null &#x26;&#x26; route != null) {
</strong>            //Route is received
        } else {
            Log.i("Directions", "Error: $error")
        }
<strong>    }
</strong><strong>    //Creating variables to use for the query
</strong><strong>    val origin = MPPoint(57.05800975, 9.949916517)
</strong>    val destination = MPPoint(57.058278, 9.9512196, 10.0)
    val stops = listOf(MPPoint(57.0582701, 9.9508396, 0.0), MPPoint(57.0580431, 9.9505475, 0.0), MPPoint(57.0580843, 9.9506085, 10.0))
    
    directionsService.query(origin, destination, stops, true)
}
</code></pre>

### Showing and configuring a multi-stop route on the map

With the introduction of the multi-stop routes. There has also been added new functionality to the `MPDirectionsRenderer` to facilitate the new multi-stop routes.

You can still render the route as a Route with stops, using `setRoute(route: MPRoute)` on the DirectionsRenderer. But the interface of the `MPDirectionsRenderer` has been expanded with a `defaultStopIcon` as well as an overload of: `setRoute(route: MPRoute, icons: HashMap<Integer, MPRouteStopIconProvider>?)`

<figure><img src="https://2554025873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZLXDaaclvaSK6Q7eigW%2Fuploads%2Fgit-blob-01869664135d37b749cde68d5bf0e18cd1c4b1f0%2FScreenshot_20240521-141733.png?alt=media" alt="" width="375"><figcaption><p>By default route stops will be shown as a red pin with numbers</p></figcaption></figure>

The `defaultStopIcon` can be configured to show any image. It can also be set to null, to not show any icon for the stops on the Route. We supply the `MPRouteStopIconConfig` that allows you to customize the default pin to fit your application.

```kotlin
//Changing the default icon to be blue, with a Meeting Room label and with no number inside the pin
val defaultRouteStopIcon = MPRouteStopIconConfig.Builder(myContext)
                                .setColor(Color.BLUE)
                                .setNumbered(false)
                                .setLabel("Meeting Room")
                                .build()
directionsRenderer?.setDefaultRouteStopIconConfig(defaultRouteStopIcon)
```

<figure><img src="https://2554025873-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYZLXDaaclvaSK6Q7eigW%2Fuploads%2Fgit-blob-67356732fbfbf946e33b2edf78deb2a4da916cd1%2FScreenshot_20240521-140958.png?alt=media" alt="" width="375"><figcaption><p>Customized MPRouteStopIcon</p></figcaption></figure>

To use your own images, you can extend the MPRouteStopIconProvider with your own class. Here is an example using a bitmap for the image

```kotlin
class BitmapRouteStopIcon(val image: Bitmap) : MPRouteStopIconProvider() {
    override fun getImage(): Bitmap? {
        return image
    }
}
```

#### Adding a custom image to a specific waypoint

It is also possible to render an image specific to a single stop. By using `setRoute(route: MPRoute, icons: HashMap<Integer, MPRouteStopIconProvider>?)`

```kotlin
val stopIcons = mapOf(2 to MPRouteStopIconConfig.Builder(this).setColor(Color.BLUE).build())
directionsRenderer?.setRoute(route, HashMap(stopIcons))
```

Here we will show a blue icon for the third stop. Leaving the first two indexes as null, means that the renderer will use the `defaultStopIcon`. If you want to render a specific known stop on an optimized route. You can find the ordering of the stops on an optimized route through `MPRoute.orderedStopIndexes`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.mapsindoors.com/sdks-and-frameworks/android/directions/using-multi-stop-navigation.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
