一旦被代码 thouter Route.Compute(...) 调用,我就使用侦听器来计算路由,但是当我退出计算的路由时,“OnRecomputeStarted”方法不会触发!这是我的代码:
Router.RouteComputeListener mRouteComputeListener = new Router.RouteComputeListener() { @Override public void onComputeError(Router router, @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);
}
};