Handling user interaction with alternative routes
After alternative routes have been visualized, it’s possible to set up a listener that will be notified when the user interacts with an alternative route.
To add a listener, use the MapManager.addAlternativeRouteListener
method, passing it the listener object which implements the MapManager.AlternativeRouteListener
interface.
Currently, the interface has a single method — onSingleTap(int[] alternativeRouteIndices)
— which is called when the user performs a single tap on alternative routes. The alternativeRouteIndices
array contains the list of indices of alternative routes that were passed to RouteVisualizer
in the latest rendering request. The array is guaranteed to have at least one item but may contain more if there was more than one alternative route near the point tapped by the user.
To remove the listener, use the MapManager.removeAlternativeRouteListener
method.
Example:
private class AlternativeRouteListener implements MapManager.AlternativeRouteListener {
@Override
public void onSingleTap(int[] alternativeRouteIndices) {
// render this route as the primary one
}
}
final AlternativeRouteListener listener = new AlternativeRouteListener();
sdk.getMapManager().addAlternativeRouteListener(alternativeRouteListener);