0

I am using here map mobile SDK for navigation for Android. Now I want to use avoidareas functionality. It is working in JS but not in Android. So if anyone have idea about this, your help would be really appreciated.

Reference URL : https://developer.here.com/documentation/routing/dev_guide/topics/example-route-avoiding-an-area.html

I am using below code.

private void createRoute() {
    /* Initialize a CoreRouter */
    CoreRouter coreRouter = new CoreRouter();


    /* Initialize a RoutePlan */
    RoutePlan routePlan = new RoutePlan();

    /*
     * Initialize a RouteOption. HERE Mobile SDK allow users to define their own parameters for the
     * route calculation,including transport modes,route types and route restrictions etc.Please
     * refer to API doc for full list of APIs
     */
    RouteOptions routeOptions = new RouteOptions();
    /* Other transport modes are also available e.g Pedestrian */
    routeOptions.setTransportMode(RouteOptions.TransportMode.CAR);
    /* Disable highway in this route. */
    routeOptions.setHighwaysAllowed(false);
    /* Calculate the shortest route available. */
    routeOptions.setRouteType(RouteOptions.Type.SHORTEST);
    /* Calculate 1 route. */
    routeOptions.setRouteCount(1);

    /* Finally set the route option */
    routePlan.setRouteOptions(routeOptions);

    RouteWaypoint startPointVs = new RouteWaypoint(new GeoCoordinate(21.1518052, 72.7792401));
    RouteWaypoint destinationPip = new RouteWaypoint(new GeoCoordinate(latDstination, lngDstination));

    MapMarker defaultMarker = new MapMarker();
    defaultMarker.setCoordinate(new GeoCoordinate(21.1518052, 72.7792401, 0.0));
    map.addMapObject(defaultMarker);

    map.setZoomLevel((map.getMaxZoomLevel() + map.getMinZoomLevel()) / 2);

    routePlan.removeAllWaypoints();

    routePlan.addWaypoint(startPointVs);
    routePlan.addWaypoint(destinationPip);

     addPolygonObject();

    /* Trigger the route calculation,results will be called back via the listener */

    coreRouter.calculateRoute(routePlan,
            new Router.Listener<List<RouteResult>, RoutingError>() {
                @Override
                public void onProgress(int i) {
                    /* The calculation progress can be retrieved in this callback. */
                }

                @Override
                public void onCalculateRouteFinished(List<RouteResult> routeResults,
                                                     RoutingError routingError) {
                    /* Calculation is done. Let's handle the result */
                    if (routingError == RoutingError.NONE) {
                        if (routeResults.get(0).getRoute() != null) {
                            /* Create a MapRoute so that it can be placed on the map */
                            m_mapRoute = new MapRoute(routeResults.get(0).getRoute());

                            /* Show the maneuver number on top of the route */
                            m_mapRoute.setManeuverNumberVisible(true);

                            /* Add the MapRoute to the map */
                            map.addMapObject(m_mapRoute);
                            /*
                             * We may also want to make sure the map view is orientated properly
                             * so the entire route can be easily seen.
                             */
                            GeoBoundingBox gbb = routeResults.get(0).getRoute()
                                    .getBoundingBox();
                            map.zoomTo(gbb, Map.Animation.NONE,
                                    Map.MOVE_PRESERVE_ORIENTATION);
                        } else {
                            Toast.makeText(activity,
                                    "Error:route results returned is not valid",
                                    Toast.LENGTH_LONG).show();
                        }
                    } else {
                        Toast.makeText(activity,
                                "Error:route calculation returned error code: " + routingError,
                                Toast.LENGTH_LONG).show();
                    }
                }
            });
}

Thank you.

user3318321
  • 21
  • 1
  • 3

1 Answers1

0

When setting up the CoreRouter for route calculation, set the dynamicPenalty property, that can penalize (addPenalty) or ban (addBannedArea) areas or concrete road elements.

Check the API reference HERE