Skip to content

Instantly share code, notes, and snippets.

@here-devblog-gists
Created April 21, 2016 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save here-devblog-gists/7c5fcdeb95b8b4b7d9e8f9934a74a1d1 to your computer and use it in GitHub Desktop.
Save here-devblog-gists/7c5fcdeb95b8b4b7d9e8f9934a74a1d1 to your computer and use it in GitHub Desktop.
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