问题描述
我利用以下code把路线覆盖到一个OSM地图机器人使用从下面的教程得到code(的),但略有调整到自定义的方法,而不是在OnCrerate方法被使用。
现在这确实路线,并产生在地图上的绿色覆盖。然而,有一个从For循环起呈现的问题。这是因为road.mNodes始终是大小为零,表明没有指令下来。
顺便说一句我还考察RoadNodes和RoadItems两者也是大小为零。这意味着气泡(ExtendedOVerlayItems)从不显示航线上。
任何意见将是极大的AP preciated。
<$p$p><$c$c>//======================================================================================================/ **
*两个geopoints之间添加一个路由覆盖与路线点泡沫覆盖。
*
* @参数的startPoint路线开始。
* @参数端点路线终点。
* //
//======================================================================================================
公共无效addRouteOverlay(GeoPoint对象的startPoint,GeoPoint的端点)
{
通过道路管理者// 1路由
RoadManager roadManager =新OSRMRoadManager();
roadManager.addRequestOption(routeType =自行车); //然后,你retreive起点和终点之间的道路:
ArrayList的&LT;&GeoPoint的GT;航点=新的ArrayList&LT;&GeoPoint的GT;();
waypoints.add(的startPoint);
waypoints.add(端点); //终点 路路= roadManager.getRoad(航点); //然后,建立与路径形状的叠加:
PathOverlay roadOverlay = RoadManager.buildRoadOverlay(道路,map.getContext());
roadOverlay.setColor(Color.GREEN);
//添加路由覆盖到地图
map.getOverlays()加(roadOverlay)。 map.invalidate(); // refesh地图 可绘制标记= ctx.getResources()getDrawable(R.drawable.map_marker_blue)。 最终的ArrayList&LT; ExtendedOverlayItem&GT; roadItems =
新的ArrayList&LT; ExtendedOverlayItem&GT;();
ItemizedOverlayWithBubble&LT; ExtendedOverlayItem&GT; roadNodes =
新ItemizedOverlayWithBubble&LT; ExtendedOverlayItem&GT;(CTX,roadItems,地图);
的for(int i = 0; I&LT; road.mNodes.size();我++)
{
RoadNode节点= road.mNodes.get(ⅰ);
ExtendedOverlayItem nodeMarker =新ExtendedOverlayItem(步+ I,,node.mLocation,CTX);
nodeMarker.setMarkerHotspot(OverlayItem.HotspotPlace.CENTER);
nodeMarker.setMarker(标记);
roadNodes.addItem(nodeMarker); nodeMarker.setDescription(node.mInstructions);
nodeMarker.setSubDescription(road.getLengthDurationText(node.mLength,node.mDuration));
可绘制图标= ctx.getResources()getDrawable(R.drawable.ic_continue)。
nodeMarker.setImage(图标); } //结束了 。map.getOverlays()加(roadNodes);}//===================================================================================================
我今天有这个问题,并设法解决它。问题在于旧版本的奖金包。我从osmbonuspack_v3.8.jar更新到版本osmbonuspack_v4.1.jar,它解决了这个问题。我还使用了MapQuestRoadManager()选项相对于OSRMRoadManager(),但其值得铭记这样做时,这几个在奖金包改超类型的方法 - 要求在ExtendedOverlayItem如的OnOpen()方法打完电话后定投它的参数。
最后RoadManager经理=新MapQuestRoadManager();
manager.addRequestOption(routeType =最快);
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);
}//===================================================================================================
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");
这篇关于下面的教程时OSMDroid路由问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!