OSMDroid Routing problems when following a tutorial
Asked Answered
G

1

1

I utilise the following code to put a route overlay onto an OSM droid map, using code gotten from the following tutorial (http://code.google.com/p/osmbonuspack/wiki/Tutorial_1) but slightly tweaked into a custom method, rather than being used in the OnCrerate method.

Now this does route and produces a green overlay on the map. However, there is a problem exhibited from the For Loop onwards. This is because road.mNodes is always size zero indicating that no instructions are coming down.

Incidently I also inspected RoadNodes and RoadItems and both were also size zero. This means the bubbles (ExtendedOVerlayItems) are never displayed on the route.

Any advice would be greatly 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);



}//===================================================================================================
Glib answered 4/2, 2013 at 17:18 Comment(1)
Did you find a solution Andrew?Duque
D
0

I had this problem today and managed to solve it. The problem lies with an old version of the bonus pack. I updated to version osmbonuspack_v4.1.jar from osmbonuspack_v3.8.jar and it solved the problem. I also used the MapQuestRoadManager() option as opposed to the OSRMRoadManager().However, its worth bearing in mind that when doing this a few of the super type methods changed in the bonus pack - such as the onOpen() method on ExtendedOverlayItem required its parameter to be cast after calling.

final RoadManager manager= new MapQuestRoadManager();
manager.addRequestOption("routeType=fastest");
Duque answered 20/11, 2013 at 11:39 Comment(1)
I have not tested this, and in the end did not develop this feature in the final application. However, your suggestion sounds plausible.Glib

© 2022 - 2024 — McMap. All rights reserved.