Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
MapGesture.OnGestureListener listener = new MapGesture.OnGestureListener.OnGestureListenerAdapter() {
public boolean onMapObjectsSelected(List<ViewObject> objects) {
// There are various types of map objects, but we only want
// to handle the MapMarkers we have added
for (ViewObject viewObj : objects) {
if (viewObj.getBaseType() == ViewObject.Type.USER_OBJECT) {
if (((MapObject)viewObj).getType() == MapObject.Type.MARKER) {
// save the selected marker to use during route calculation
selectedMapMarker = ((MapMarker) viewObj);
// Create the RoutePlan and add two waypoints
RoutePlan routePlan = new RoutePlan();
// Use our current position as the first waypoint
routePlan.addWaypoint(new GeoCoordinate(
// Use the marker's position as the second waypoint
routePlan.addWaypoint(new GeoCoordinate(
((MapMarker) viewObj).getCoordinate()));
// Create RouteOptions and set to fastest & pedestrian mode
RouteOptions routeOptions = new RouteOptions();
// Create a RouteManager and calculate the route
RouteManager rm = new RouteManager();
rm.calculateRoute(routePlan, new RouteListener());
// Remove all other markers from the map
for (MapObject mapObject : placesContainer.getAllMapObjects()) {
if (!mapObject.equals(viewObj)) {
// If user has tapped multiple markers, just display one route
// return false to allow the map to handle this callback as well
return false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment