0

I have a list of areas which are made up of multiple "boxes" (or avoidance areas). I am trying to add these boxes to the avoidance options when calculating the route, but the route seems to just ignore avoidance areas and create a route going through the avoidance areas.

I tried adding the areas to the avoidance options by creating GeoBox objects using GeoCoordinates.

CarOptions carOptions = new CarOptions();

for (Area area : closest100Areas) {
    for (Box box : area.getBoxes()) {
        GeoCoordinates northEast = new GeoCoordinates(box.northEast.latitude, box.northEast.longitude);
        GeoCoordinates southWest = new GeoCoordinates(box.southWest.latitude, box.southWest.longitude);
        carOptions.avoidanceOptions.avoidAreas.add(new GeoBox(southWest, northEast));
    }
}

routingEngine.calculateRoute(waypoints, carOptions, new CalculateRouteCallback() {
    @Override
    public void onRouteCalculated(@Nullable RoutingError routingError, @Nullable List<Route> routes) {
        if (routingError == null) {
            Route route = routes.get(0);
            showRouteDetails(route);
            showRouteOnMap(route);
            getManeuverInstructions(route);
            logRouteViolations(route);
        } else {
            Log.e("Error while calculating a route:", routingError.toString());
        }
    }
});

The attached image shows a highlighted avoidance area which seems to be ignored. I also am not sure as to why there is a noticeable notch, but that is a separate issue.

user16217248
  • 3,119
  • 19
  • 19
  • 37
Todd
  • 15
  • 2

1 Answers1

0

You can take a look at this guide.

You already call logRouteViolations(route). If it is was not possible to by-pass the areas, then a SectionNotice will be generatd.

You can then decide if you want to reject such routes.

You can detect possible route notices like this:

// A route may contain several warnings, for example, when a certain route option could not be fulfilled.
// An implementation may decide to reject a route if one or more violations are detected.
private void logRouteViolations(Route route) {
    for (Section section : route.getSections()) {
        for (SectionNotice notice : section.getSectionNotices()) {
            Log.e(TAG, "This route contains the following warning: " + notice.code.toString());
        }
    }
}

In case of areas, you will most likely see VIOLATED_BLOCKED_ROAD notices.

Nusatad
  • 3,231
  • 3
  • 11
  • 17