Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MapGesture.OnGestureListener listener = new MapGesture.OnGestureListener.OnGestureListenerAdapter() {
@Override
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(
posManager.getPosition().getCoordinate()));
// 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();
routeOptions.setTransportMode(RouteOptions.TransportMode.PEDESTRIAN);
routeOptions.setRouteType(RouteOptions.Type.SHORTEST);
routePlan.setRouteOptions(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)) {
placesContainer.removeMapObject(mapObject);
}
}
// If user has tapped multiple markers, just display one route
break;
}
}
}
// 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
You can’t perform that action at this time.