Search code examples
javaroutesosmdroidgraphhopper

OSMBonusPack with Graphhopper routing API


I am building an application where I am using osmdroid with its bonus pack and mapnik for tiles. I want to be able to output shortest path between multiples points, and as a next step build paths considering time-frames. From my research it looks like Graphhopper Routing Optimization API is exactly what I need, but I can't figure out how to use it in my project properly. Since I am using os OSMBonusPack it looks like my only option is to set up Road Manager properly to be able to use routing optimization. Following tutorial for OSMBonusPack I am able to create Road manager and draw paths from one point to another, but not sure how to add optimization to find shortest path to it as well as set the road type to be "pedestrian" not a car. Any help will be highly appreciated. That's the code I am using to build a path between my points, pretty much exactly the same as tutorial:

 ArrayList<GeoPoint> waypoints = new ArrayList<GeoPoint>();
                    for (int i = 0; i < chosenAttractions.size(); i++) {
                        GeoPoint point = new GeoPoint(chosenAttractions.get(i).latitude, chosenAttractions.get(i).longitude);
                        waypoints.add(point);
                    }

                if (count > 1) {
                    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
                    StrictMode.setThreadPolicy(policy);
                    RoadManager roadManager = new GraphHopperRoadManager("fae5bf0a-402a-48b2-96ac-324e138f53dc", true);

                  //  roadManager.addRequestOption("routeType=bicycle");
                    Road road = roadManager.getRoad(waypoints);
                    Polyline roadOverlay = RoadManager.buildRoadOverlay(road);
                    map.getOverlays().add(roadOverlay);
                    map.invalidate();

                }
            }

Solution

  • Turns out to use optimization or vehicle option of Routing API one has to pass it as an argument to addRequestOption function, for example:

    roadManager.addRequestOption("vehicle=foot");
    roadManager.addRequestOption("optimize=true");