OnRecomputeFinished не будет вызван

Я использую слушатель для вычисления маршрута, как только он вызван через анализатор маршрута Route.Compute(...), но когда я выхожу из вычисленного маршрута, метод "OnRecomputeStarted" не срабатывает! это мой код:

Router.RouteComputeListener mRouteComputeListener = new Router.RouteComputeListener () {@Override public void onComputeError (Маршрутизатор маршрутизатора, @Router.RouteComputeError int error) {

        }

        @Override
        public void onProgress(Router router, int progress, int routeIndex) {

            // update progress
        }

        @Override
        public void onComputeStarted(Router router) {
        }

        @SuppressLint("SetTextI18n")
        @Override
        public void onPrimaryComputeFinished(Router router, com.sygic.sdk.route.RouteInfo routeInfo) {

            mapRoutePrimary = new MapRoute(routeInfo, MapRoute.RouteType.Primary); // routeInfo  is obtained via onPrimaryComputeFinished() method in RouteComputeListener
            mpView.addMapObject(mapRoutePrimary);

        }

        @Override
        public void onAlternativeComputeFinished(Router router, com.sygic.sdk.route.RouteInfo routeInfo) {
            mapRouteAlternative = new MapRoute(routeInfo, MapRoute.RouteType.Alternative); // routeInfo  is obtained via onAlternativeComputeFinished() method in RouteComputeListener
            mpView.addMapObject(mapRouteAlternative);

            for (RouteManeuver maneuver : routeInfo.getManeuvers()) {
                directionText.setText(maneuver.getType()+" "+directionText.getText());

            }

        }

        @Override
        public void onComputeFinished(Router router) {
            NavigationManager.getInstance().setRouteForNavigation(mapRoutePrimary.getRouteInfo());
            if (mapRouteAlternative!=null)
                mapRoutePrimary.getRouteInfo().getBoundingBox().union(mapRouteAlternative.getRouteInfo().getBoundingBox());
            Objects.requireNonNull(mpView.getCamera()).setMapRectangleWithMargin(mapRoutePrimary.getRouteInfo().getBoundingBox(),mapAnimation,15,15,15,15);

            NavigationManager.getInstance().addOnDirectionListener(new NavigationManager.OnDirectionListener() {
                @Override
                public void onDirectionInfoChanged(@NonNull DirectionInfo directionInfo) {
                    final int distance = directionInfo.getDistance();
                    final int nextDistance = directionInfo.getNextDistance();

                    final RouteManeuver primaryManeuver = directionInfo.getPrimary();
                    if (primaryManeuver != null) {
                        final int type = primaryManeuver.getType();
                        final String roadName = primaryManeuver.getRoadName();
                        final String nextRoadName = primaryManeuver.getNextRoadName();
                        directionText.setText(roadName);

                        Log.d("directions", "direction of type " + type + " on the road " + roadName + ". Next road is " + nextRoadName);
                        //Toast.makeText(getApplicationContext(), "direction of type " + type + " on the road " + roadName + ". Next road is " + nextRoadName,Toast.LENGTH_LONG).show();
                    }
                }
            });
        }

        @Override
        public void onRecomputeStarted() {
            // called when recompute was invoked. Recompute can be invoked after leaving computed route
            mpView.removeMapObject(mapRoutePrimary);
        }

        @Override
        public void onRecomputeFinished(com.sygic.sdk.route.RouteInfo routeInfo, int i) {
            mpView.removeMapObject(mapRoutePrimary);

            mapRoutePrimary = new MapRoute(routeInfo, MapRoute.RouteType.Primary); 
            mpView.addMapObject(mapRoutePrimary);
        }
    };

0 ответов

OnRecomputeStarted слушает Router.recomputeRoute() метод. Что вам, вероятно, нужно, это слушать NavigationManager.OnRouteChangedListener, Итак, в основном это код:

NavigationManager.getInstance().addOnRouteChangedListener(new NavigationManager.OnRouteChangedListener() {
    @Override
    public void onRouteChanged(final RouteInfo newRouteInfo) {
        mpView.removeMapObject(mapRoutePrimary);
        // set newRouteInfo as new route for navigation...
    }
});
Другие вопросы по тегам