How to display Route on my OSM application

ⅰ亾dé卋堺 提交于 2019-12-11 08:22:46

问题


In log

02-19 14:41:29.151  10336-10336/com.example.app E/BONUSPACK﹕ OSRMRoadManager::getRoad: request failed.

02-19 14:41:29.151  10336-10336/com.example.app I/System.out﹕ 2

and I have route.gpx file but i don't know how to use it

    GeoPoint startPoint = new GeoPoint(48.13, -1.63);

    mapView = (MapView) findViewById(R.id.mapview);
    mapCTRL = (MapController) mapView.getController();

    mapCTRL.setZoom(13);
    mapView.setBuiltInZoomControls(true);
    mapCTRL.setCenter((new GeoPoint(startPoint)));

    RoadManager roadManager = new OSRMRoadManager();
    ArrayList<GeoPoint> waypoints = new ArrayList<GeoPoint>();
    waypoints.add(startPoint);
    //waypoints.add(new GeoPoint(16.236505, 103.264646)); //end point บ้านดินดำ
    waypoints.add(new GeoPoint(48.4, -1.9)); //end point

    Road road = roadManager.getRoad(waypoints);
    System.out.println(road.mStatus);

    Polyline roadOverlay = RoadManager.buildRoadOverlay(road, this);
    mapView.getOverlays().add(roadOverlay);
    mapView.invalidate();

    setContentView(mapView);

    mapView.invalidate();

回答1:


Assuming you plan to use an online routing service, this question should be linked to this one: RoadManager for osmdroid error

Assuming you want to have an offline routing system, then using OSRMRoadManager (which uses OSRM online service) is irrelevant. You could have a look at offline routing software, like GraphHopper.




回答2:


new Thread(new Runnable()
{
    public void run() 
    {
        RoadManager roadManager = new OSRMRoadManager();
        ArrayList<GeoPoint> waypoints = new ArrayList<GeoPoint>();
        GeoPoint startPoint = new GeoPoint(source_lat, source_longi);               
        waypoints.add(startPoint);
        GeoPoint endPoint = new GeoPoint(desti_lat,desti_longi);
        waypoints.add(endPoint);                    
        try 
        {
            road = roadManager.getRoad(waypoints);
        } 
        catch (Exception e)
        {
            e.printStackTrace();
        }

        runOnUiThread(new Runnable() 
        {
            public void run() 
            {
                if (road.mStatus != Road.STATUS_OK)
                {
                      //handle error... warn the user, etc. 
                }

                Polyline roadOverlay = RoadManager.buildRoadOverlay(road, Color.RED, 8, context);
                map.getOverlays().add(roadOverlay);                 
            }
        });
    }
}).start(); 

And i am use two jar files 1)slf4j-android-1.5.8.jar and 2)osmdroid-android-4.2.jar and osmbonuspack library.


来源:https://stackoverflow.com/questions/21874351/how-to-display-route-on-my-osm-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!