想要在导航中添加途径点,然后再手动与调用方法删除途经点。 看高德导航SDK中,找到了添加途径点的方法,但没有点击途经点的回调。
时间: 2024-03-13 20:44:44 浏览: 24
在高德导航SDK中,可以使用AMapNaviListener接口来监听导航过程中的各种事件,包括途经点的点击回调。具体的步骤如下:
1. 在初始化导航时,设置AMapNaviListener对象:
```
mAMapNavi = AMapNavi.getInstance(getApplicationContext());
mAMapNavi.addAMapNaviListener(this);
```
2. 实现AMapNaviListener接口中的onNaviInfoUpdate方法,该方法会在导航过程中被多次调用,可以通过AMapNaviInfo对象获取当前导航信息:
```
@Override
public void onNaviInfoUpdate(NaviInfo naviInfo) {
// 获取当前导航信息,包括途经点信息
int allLength = naviInfo.getPathRetainDistance();
int curStepRetainLength = naviInfo.getCurStepRetainDistance();
int curStepRetainTime = naviInfo.getCurStepRetainTime();
int curStep = naviInfo.getCurStep();
int pathLength = naviInfo.getPathLength();
int iconType = naviInfo.getIconType();
String curRoadName = naviInfo.getCurrentRoadName();
String nextRoadName = naviInfo.getNextRoadName();
String nextRoadDistance = naviInfo.getNextRoadDistance();
String nextRoadTime = naviInfo.getNextRoadTime();
String routeRemainDistance = naviInfo.getRouteRemainDistance();
String routeRemainTime = naviInfo.getRouteRemainTime();
String routeAllDistance = naviInfo.getRouteAllDistance();
String curStepName = naviInfo.getCurStepName();
String curStepDistance = naviInfo.getCurStepDistance();
String curStepTime = naviInfo.getCurStepTime();
int curSpeed = naviInfo.getCurSpeed();
int limitSpeed = naviInfo.getLimitSpeed();
int cameraType = naviInfo.getCameraType();
int cameraDistance = naviInfo.getCameraDistance();
int cameraSpeed = naviInfo.getCameraSpeed();
int curLink = naviInfo.getCurLink();
int curPoint = naviInfo.getCurPoint();
List<NaviLatLng> coordList = naviInfo.getCoordList();
List<NaviLatLng> linkCoordList = naviInfo.getLinkCoordList();
List<Integer> linkIndexList = naviInfo.getLinkIndexList();
List<Integer> pointIndexList = naviInfo.getPointIndexList();
List<NaviLatLng> pathLatLngList = naviInfo.getPathLatLngList();
List<NaviLatLng> allCoordList = naviInfo.getAllCoordList();
List<Integer> allLengthList = naviInfo.getAllLengthList();
List<Integer> allTimeList = naviInfo.getAllTimeList();
List<NaviTrafficStatus> trafficStatuses = naviInfo.getTrafficStatuses();
int pathRetainDistance = naviInfo.getPathRetainDistance();
int pathRetainTime = naviInfo.getPathRetainTime();
int curLinkRetainDistance = naviInfo.getCurLinkRetainDistance();
int curLinkRetainTime = naviInfo.getCurLinkRetainTime();
int pathTrafficLightNumber = naviInfo.getPathTrafficLightNumber();
int routeTrafficLightNumber = naviInfo.getRouteTrafficLightNumber();
int pathTollCost = naviInfo.getPathTollCost();
int totalTollCost = naviInfo.getTotalTollCost();
int curStepProgress = naviInfo.getCurStepProgress();
int pathTrafficType = naviInfo.getPathTrafficType();
int routeTrafficType = naviInfo.getRouteTrafficType();
int pathCrossCoor = naviInfo.getPathCrossCoor();
int pathRestriction = naviInfo.getPathRestriction();
// 判断是否到达了途经点
List<NaviLatLng> wayPointList = mAMapNavi.getWayPointList();
if (wayPointList != null && wayPointList.size() > 0) {
int[] wayIndexs = mAMapNavi.getWayPointIndex();
for (int i = 0; i < wayIndexs.length; i++) {
if (wayIndexs[i] == curPoint) {
// 到达了第i个途经点,可以在此处处理途经点的点击回调
// ...
}
}
}
}
```
在onNaviInfoUpdate方法中,通过调用mAMapNavi.getWayPointList()方法获取途经点列表,然后再通过mAMapNavi.getWayPointIndex()方法获取各个途经点的索引,最后判断当前点是否到达了某个途经点,从而触发点击回调。
3. 在导航结束时,移除AMapNaviListener对象:
```
mAMapNavi.removeAMapNaviListener(this);
```
以上就是在高德导航SDK中监听途经点点击回调的方法,希望能对您有所帮助。