solarrobor
solarrobor

Reputation: 11

Unable to display route on Osmdroid map

I am unable to get a route displayed on a Osmdroid map displayed on an Android 4.3 smartphone. I am using osmbonuspack v4.4 jar and osmdroid-android v4.1 jar. I have overriden/copied OSRMRoadManager to CarRouteManager so that it makes use of the java.net.HttpURLConnection instead of the Apache HTTPConnection. With Apache HTTPConnection I don't get any route information back but with the java.net.HttpURLConnection I get route information back. The road has a mStatus of STATUS_OK and I can see the various parts of the route when I debug my code. The route drawing function is the following:

public void DrawDirection(Road road)
{
    if (road.mStatus == Road.STATUS_OK)
    {
        current_route = CarRouteManager.buildRoadOverlay(road, Color.BLUE, 3, this);
        current_route.addPoint(user_point);
        current_route.addPoint(clicked_location);
        map_view.getOverlays().add(current_route);          
        map_view.invalidate();
    }
}

With the above code I just get two polylines displayed on the map, one which traces straight from the GeoPoint user_point(starting point) to the GeoPoint clicked_location (destination). The other polyline traces to the right-bottom of the screen and off the current map area that is visible, when I zoom out to the world map it extends all the way off the edge of the map at Antartica. When I remove the two lines

current_route.addPoint(user_point);

and

current_route.addPoint(clicked_location);

then there are no polylines drawn on the map. I have debugged the contents of current_route (which is of type PathOverlay) and the points in the mPoints array are valid GeoPoints, i.e. not null. When I map these GeoPoints onto the Google map at https://maps.google.com/ then it shows that these GeoPoints are valid locations on the roads/route between GeoPoint user_point(starting point) and GeoPoint clicked_location (destination).

Has anybody suffered the same affect and managed to solve it?

Upvotes: 1

Views: 2800

Answers (1)

MKer
MKer

Reputation: 3450

I would recommend you to:

  • get rid of your CarRouteManager stuff
  • just follow closely the OSMBonusPack tutorial
  • taking care about the "Important Note" at the very beginning of the Tutorials.

If you still have issues, have a look here: RoadManager for osmdroid error

Only when you will have a better understanding of the inner behaviour of the lib, you will be able to implement your own RouteManager (if really needed).

Upvotes: 1

Related Questions