I use the following code to overlay a route overlay on an OSM droid map using the code obtained from the following tutorial ( http://code.google.com/p/osmbonuspack/wiki/Tutorial_1 ) but slightly modified to a custom method, not used in the OnCrerate method.
Now this is the route and creates a green overlay on the map. However, there is a problem manifested in For Loop onwards. This is because road.mNodes is always zero, indicating that the instructions do not go down.
By the way, I also inspected RoadNodes and RoadItems, and both of them were also zero. This means that bubbles (ExtendedOVerlayItems) are never displayed on the route.
Any advice is appreciated.
//====================================================================================================== /** * Add a route overlay between two geopoints with Bubble overlays on the route points. * * @param startPoint Route start. * @param endPoint Route end. *// //====================================================================================================== public void addRouteOverlay(GeoPoint startPoint, GeoPoint endPoint) { //1 Routing via road manager RoadManager roadManager = new OSRMRoadManager(); roadManager.addRequestOption("routeType=bicycle"); //Then, retreive the road between your start and end point: ArrayList<GeoPoint> waypoints = new ArrayList<GeoPoint>(); waypoints.add(startPoint); waypoints.add(endPoint); //end point Road road = roadManager.getRoad(waypoints); // then, build an overlay with the route shape: PathOverlay roadOverlay = RoadManager.buildRoadOverlay(road, map.getContext()); roadOverlay.setColor(Color.GREEN); //Add Route Overlays into map map.getOverlays().add(roadOverlay); map.invalidate();//refesh map Drawable marker = ctx.getResources().getDrawable(R.drawable.map_marker_blue); final ArrayList<ExtendedOverlayItem> roadItems = new ArrayList<ExtendedOverlayItem>(); ItemizedOverlayWithBubble<ExtendedOverlayItem> roadNodes = new ItemizedOverlayWithBubble<ExtendedOverlayItem>(ctx, roadItems, map); for (int i=0; i<road.mNodes.size(); i++) { RoadNode node = road.mNodes.get(i); ExtendedOverlayItem nodeMarker = new ExtendedOverlayItem("Step "+i, "", node.mLocation, ctx); nodeMarker.setMarkerHotspot(OverlayItem.HotspotPlace.CENTER); nodeMarker.setMarker(marker); roadNodes.addItem(nodeMarker); nodeMarker.setDescription(node.mInstructions); nodeMarker.setSubDescription(road.getLengthDurationText(node.mLength, node.mDuration)); Drawable icon = ctx.getResources().getDrawable(R.drawable.ic_continue); nodeMarker.setImage(icon); }//end for map.getOverlays().add(roadNodes); }//===================================================================================================
source share