0

我在这里使用地图移动 SDK进行 Android 导航。现在我想使用避免区域功能。它适用于 JS,但不适用于 Android。因此,如果有人对此有所了解,我们将非常感谢您的帮助。

参考网址:https ://developer.here.com/documentation/routing/dev_guide/topics/example-route-avoiding-an-area.html

我正在使用下面的代码。

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

谢谢你。

4

1 回答 1

0

在设置 CoreRouter 进行路线计算时,设置 dynamicPenalty 属性,可以惩罚(addPenalty)或禁止(addBannedArea)区域或混凝土道路元素。

在此处查看 API 参考

于 2020-11-10T08:31:17.497 回答