遵循教程时OSMDroid路由问题

时间:2013-02-04 17:18:52

标签: android map routing osmdroid openstreetmap

我利用以下代码将路径覆盖放到OSM机器人地图上,使用从以下教程(http://code.google.com/p/osmbonuspack/wiki/Tutorial_1)获得的代码,但略微调整为自定义方法,而不是在OnCrerate方法中使用。

现在这会路由并在地图上生成绿色叠加层。但是,从For循环开始出现问题。这是因为road.mNodes总是大小为零,表示没有指令正在关闭。

我还特意检查了RoadNodes和RoadItems,两者的大小也是零。这意味着气泡(ExtendedOVerlayItems)永远不会显示在路线上。

非常感谢任何建议。

//======================================================================================================
/**
 *  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);



}//===================================================================================================

1 个答案:

答案 0 :(得分:0)

我今天遇到了这个问题,并设法解决了这个问题。问题在于旧版的奖金包。我从osmbonuspack_v3.8.jar更新到版本osmbonuspack_v4.1.jar,它解决了这个问题。我还使用了MapQuestRoadManager()选项而不是OSRMRoadManager()。但是,值得注意的是,在执行此操作时,奖励包中的一些超类型方法发生了变化 - 例如,需要在ExtendedOverlayItem上使用onOpen()方法调用后要播放的参数。

final RoadManager manager= new MapQuestRoadManager();
manager.addRequestOption("routeType=fastest");