路线显示为直线而不是沿着OSM地图中的任何道路

时间:2014-04-29 05:33:47

标签: java android android-mapview openstreetmap osmdroid

我使用OSM地图创建了一个App。该应用程序工作正常,但从我当前位置到目的地的路线显示为一条直线,而不是通过任何道路。

我正在使用的方法

public void addRouteOverlay(GeoPoint startPoint, GeoPoint endPoint) {
            // road manager
            RoadManager roadManager = new OSRMRoadManager();

            // start and end points
            ArrayList<GeoPoint> waypoints = new ArrayList<GeoPoint>();
            waypoints.add(startPoint);
            // GeoPoint endPoint = new GeoPoint(48.4, -1.9);
            waypoints.add(endPoint);
            // roadManager.addRequestOption("routeType=bicycle");
            // retreive the road between those points
            Road road = roadManager.getRoad(waypoints);
            if (road.mStatus != Road.STATUS_OK){
                  Log.d("Road Status", ""+road.mStatus);
                }
            // Polyline with the route shape
            org.osmdroid.bonuspack.overlays.Polyline roadOverlay = RoadManager
                    .buildRoadOverlay(road, this);
            // Polyline to the overlays of your map
            mapView.getOverlays().add(roadOverlay);
            // Refresh the map
            mapView.invalidate();  

我调用方法的方式

//to display route between current location and destination
                addRouteOverlay(new GeoPoint(location.getLatitude(),
                        location.getLongitude()), new GeoPoint(22.566039700000000000,
                                88.349356700000040000));

我该怎么做才能在我的位置和目的地之间找到理想的路线?

0 个答案:

没有答案