Search code examples
androidopenstreetmaposmdroid

How to display Route on my OSM application


it show straight line

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();

Solution

  • 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.