怎么清除上一次的路线,并且显示新路线 代码
时间: 2023-08-18 10:05:21 浏览: 181
你可以使用AMapNavi类中的以下方法来清除上一次的路线,并显示新路线:
1.在AMapNavi对象初始化时,设置导航监听器
```
AMapNavi.getInstance(context).addAMapNaviListener(this);
```
2.在导航监听器中,调用onCalculateRouteSuccess方法,该方法会在计算路线成功时回调:
```
@Override
public void onCalculateRouteSuccess(int[] ints) {
// 清除上一次的路线
mAMapNaviView.getMap().clear();
// 显示新路线
mAMapNaviView.getMap().setMapTextZIndex(0);
mAMapNaviView.getMap().setMyLocationEnabled(true);
mAMapNaviView.getMap().setMyLocationStyle(new MyLocationStyle().myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER));
mAMapNaviView.getMap().setTrafficEnabled(true);
mAMapNaviView.getMap().setCustomMapStylePath("...");
mAMapNaviView.getMap().setCustomMapStyleID("...");
mAMapNaviView.getMap().setMapLanguage("...");
mAMapNaviView.getMap().setMapType(AMap.MAP_TYPE_NORMAL);
mAMapNaviView.getMap().setOnMapLoadedListener(new AMap.OnMapLoadedListener() {
@Override
public void onMapLoaded() {
mAMapNaviView.getMap().moveCamera(CameraUpdateFactory.changeTilt(0));
}
});
// 显示导航界面
mAMapNaviView.setVisibility(View.VISIBLE);
mAMapNaviView.startNavi(NaviType.GPS);
}
```
上述代码中,清除上一次的路线使用了`mAMapNaviView.getMap().clear()`方法,显示新路线使用了一系列设置地图属性的方法,其中包括开启实时交通、设置自定义地图样式等。
最后,调用`mAMapNaviView.startNavi(NaviType.GPS)`方法开始导航。