RoadManager for osmdroid 错误 [英] RoadManager for osmdroid error

查看:15
本文介绍了RoadManager for osmdroid 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里学习教程 https://code.google.com/p/osmbonuspack/wiki/Tutorial_1 但我遇到了一个错误,它没有正确显示正确的路线.它只是显示了从 A 点到 B 点的直线.

I am following a tutorial here https://code.google.com/p/osmbonuspack/wiki/Tutorial_1 but I have encountered an error that it doesn't show the correct route correctly. It just shows a straight line from Point A to Point B.

我想要实现的是从这些点显示正确的路线.我猜错误是它无法识别任何要通过的节点.

What I want to achieve is to show the correct route from these points. I'm guessing the error is that it doesn't recognize any nodes to go through.

也有人问了一个类似的问题,如果我没有很好地解释我的问题,我假设我有同样的问题.

A similar question has been also asked and I am assuming I have the same problem if I haven't explained my question well.

可以在这里找到类似的问题:OSMDroid Routing questions when following a tutorial

Similar question can be found here: OSMDroid Routing problems when following a tutorial

这是我使用 RoadManager 的代码的一部分

Here is a part of my code using RoadManager

这是部分代码.

try {

                //get current longlat
                gpsLocator.getLocation(); 
                cur_loc_lat =gpsLocator.getLatitude();
                cur_loc_long =gpsLocator.getLongitude(); 

            } catch (Exception e) {
                // TODO: handle exception
            }

            //--- Create Another Overlay for multi marker
            anotherOverlayItemArray = new ArrayList<OverlayItem>();
            anotherOverlayItemArray.add(new OverlayItem(
                    "UST", "UST", new GeoPoint( testlat, testlong))); 

            //--- Create Another Overlay for multi marker 
            anotherOverlayItemArray.add(new OverlayItem(
                    locDefine[0], "UST", new GeoPoint( sel_latitude, sel_longitude))); 


            ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay 
             = new ItemizedIconOverlay<OverlayItem>(
               TomWalks.this, anotherOverlayItemArray, myOnItemGestureListener);

            myOpenMapView.getOverlays().add(anotherItemizedIconOverlay);
            //---

            //Add Scale Bar
            ScaleBarOverlay myScaleBarOverlay = new ScaleBarOverlay(TomWalks.this);
            myOpenMapView.getOverlays().add(myScaleBarOverlay);


           try {


               //1 Routing via road manager
                RoadManager roadManager = new MapQuestRoadManager();
                roadManager.addRequestOption("routeType=pedestrian"); 
                /*
                roadManager.addRequestOption("units=m"); 
                roadManager.addRequestOption("narrativeType=text"); 
                roadManager.addRequestOption("shapeFormat=raw"); 
                roadManager.addRequestOption("direction=0");  
                */
                //Then, retrieve the road between your start and end point:
                ArrayList<GeoPoint> waypoints = new ArrayList<GeoPoint>();
                waypoints.add(new GeoPoint(testlat, testlong));
                waypoints.add(new GeoPoint(sel_latitude,sel_longitude)); //end point

                Road road = roadManager.getRoad(waypoints);


                // then, build an overlay with the route shape:
                PathOverlay roadOverlay = RoadManager.buildRoadOverlay(road, myOpenMapView.getContext());
                roadOverlay.setColor(Color.GREEN);


                //Add Route Overlays into map
                myOpenMapView.getOverlays().add(roadOverlay);
                myOpenMapView.invalidate();//refesh map


                final ArrayList<ExtendedOverlayItem> roadItems = 
                          new ArrayList<ExtendedOverlayItem>();
                ItemizedOverlayWithBubble<ExtendedOverlayItem> roadNodes = 
                          new ItemizedOverlayWithBubble<ExtendedOverlayItem>(TomWalks.this, roadItems, myOpenMapView);



                myOpenMapView.getOverlays().add(roadNodes);
                myOpenMapView.invalidate();//refesh map



                int nodesize=road.mNodes.size();
                double length = road.mLength;


                Drawable    marker = getResources().getDrawable(R.drawable.marker_node);

                Toast.makeText(TomWalks.this, " Distance : " + length + " Nodes : "+nodesize ,Toast.LENGTH_SHORT).show();

                  for (int i=0; i<road.mNodes.size(); i++)
                  {
                          RoadNode node = road.mNodes.get(i);
                          ExtendedOverlayItem nodeMarker = new ExtendedOverlayItem("Step "+i, "", node.mLocation, TomWalks.this);
                          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 = getResources().getDrawable(R.drawable.marker_node);
                          nodeMarker.setImage(icon);

                  }//end for

                  myOpenMapView.getOverlays().add(roadNodes);
                  myOpenMapView.invalidate();//refesh map


            } catch (Exception e) {
                // TODO: handle exception


                Toast.makeText(TomWalks.this,e.getMessage(),Toast.LENGTH_SHORT).show();


            } 

            myMapController.setCenter(new GeoPoint( sel_latitude,  sel_longitude));


        } catch (Exception e) {
            // TODO: handle exception
        }           
    }

}

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

推荐答案

让我们尝试为这个非常常见的问题提供一个完整的答案.

Let's try to provide a complete answer to this quite frequent question.

基本上,当你得到直线"时,这意味着 RoadManager 出错了.

Basically, when you get the "straight line", it means that the RoadManager got an error.

所以,首先,在你的代码中,你应该检查getRoad的结果,这样:

So, first of all, in your code, you should check the result of getRoad, this way:

if (road.mStatus != Road.STATUS_OK){
  //handle error... warn the user, etc. 
}

现在,这个错误来自哪里?=> 你必须在 logcat 中搜索.您应该找到已发送的完整 url,可能还有关于错误的堆栈跟踪.

Now, where this error is coming from? => You must search in the logcat. You should find the full url that has been sent, and probably a stacktrace about the error.

我强烈建议您在浏览器中复制/粘贴此完整网址,然后检查结果.

I strongly recommend that you copy/paste this full url in a browser , and check the result.

以下是典型的错误,按概率递减:

Here are the typical errors, by decreasing probability:

1) 您没有仔细阅读Tutorial_0,并且您正尝试在主线程中使用 SDK >= 3.0 进行网络调用.=> 阅读此重要提示".

1) You didnt' read carefully the "Important note" at the beginning of the Tutorial_0, and you are trying to do a Network call in the main thread, with an SDK >= 3.0. => Read this "Important note".

2) 你要求的路线是不可能的(真的不可能,或者因为奇怪的位置,或者因为设置了不受支持的选项).=> 这很容易通过在网络浏览器中复制/粘贴完整的 url 并查看答案来检查.

2) You asked for a route that is not possible (really not possible, or because of weird positions, or because of setting unsupported options). => This is easy to check by copy/pasting the full url in a web browser, and looking at the answer.

3) 您的设备没有网络连接.

3) Your device has no network connectivity.

4) 路由服务更改了它的 API(这种情况发生了不止一次……).=> 可以通过在浏览器中复制/粘贴完整的 url 来检查.在这种情况下,请在 OSMBonusPack 项目中提出问题,以便我们尽快将其考虑在内.

4) The routing service changed its API (this happened, more than once...). => Could be checked by copy/pasting the full url in a browser. In this case, raise an Issue in OSMBonusPack project, so that we can take it into account ASAP.

5) 路由服务已关闭.=> 通过在浏览器中复制/粘贴完整的 url 很容易检查.

5) The routing service is down. => Easy to check by copy/pasting the full url in a browser.

这篇关于RoadManager for osmdroid 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆