The class MPDirectionsService is used to request routes from one point to another. The minimum required input to receive a route is an origin and a destination.
This example shows how to setup and execute a query for a Route:
The route can be customized via the directionsRenderer. An example could be the color of the rendered path and the background color of the rendered line. This can be set like this:
val directionsRenderer =MPDirectionsRenderer(mapControl)directionsRenderer.setPolylineColors(Color.GREEN, Color.BLACK)
In MapsIndoors, the transportation mode is referred to as travel mode. There are four travel modes, walking, bicycling, driving and transit (public transportation). The travel modes generally applies for outdoor navigation. Indoor navigation calculations are based on walking travel mode.
Set the travel mode on your request using the setTravelMode method on MPDirectionsService:
funcreateRoute(mpLocation: MPLocation) {// if MPDirectionsService has not been instantiated create it here and assign the results call back to the activity.if (mpDirectionsService ==null) { mpDirectionsService =MPDirectionsService() mpDirectionsService?.setRouteResultListener(this::onRouteResult) } mpDirectionsService?.setTravelMode(MPTravelMode.WALKING)// queries the MPDirectionsService for a route with the hardcoded user location and the point from a location. mpDirectionsService?.query(mUserLocation, mpLocation.point)}
voidcreateRoute(MPLocation mpLocation) {// if MPDirectionsService has not been instantiated create it here and assign the results call back to the activity.if (mpDirectionsService ==null) { mpDirectionsService =newMPDirectionsService();mpDirectionsService.setRouteResultListener(this::onRouteResult); }mpDirectionsService.setTravelMode(MPTravelMode.WALKING);// queries the MPDirectionsService for a route with the hardcoded user location and the point from a location.mpDirectionsService.query(mUserLocation,mpLocation.getPoint());}
The travel modes generally only apply for outdoor navigation. Indoor navigation calculations are based on the walking travel mode.
There are several ways to influence the calculated route by applying various restrictions to the directions query:
Avoid and/or exclude certain way types under certain circumstances
Apply restrictions based on User Roles
Avoid and exclude way types
It is possible to avoid and/or exclude certain way types when calculating a route. Avoiding a way type means that DirectionsService will do its best to find a route without the avoided way types, but if no route can be found without them, it will try to find a route where the avoided way types may be used. To eliminate certain way types entirely, add them as excluded way types. If a way type is both avoided and excluded, excluded will be obeyed.
It may for example be desirable to provide a route better suited for users with physical disabilities by avoiding e.g. stairs. This can be achieved by avoiding that way type on the route using the avoidWayTypes property:
val directionsService: MPDirectionsService=MPDirectionsService()directionsService.addAvoidWayType(MPHighway.STEPS)
In an emergency situation it may be required to not use elevators at all. This can be achieved by adding the way type elevator to the excludeWayTypes property:
val directionsService: MPDirectionsService=MPDirectionsService()directionsService.addExcludeWayType(MPHighway.ELEVATOR)
When Route restrictions are set on the MPDirectionsService they will be applied to any subsequent queries as well. You can remove them again by calling clearAvoidWayType or clearExcludeWayType.
val directionsService: MPDirectionsService=MPDirectionsService()directionsService.clearAvoidWayType()directionsService.clearExcludeWayType()
When using the Transit travel mode, you must set a departure date or an arrival date on the route using the setTime method on MPDirectionsService and declaring if it is a departure or not through setIsDeparture. The date parameter is the epoch time, in seconds, as an integer, and it is only possible to use one of these properties at a time.