记录一下。android接入高德API出现的问题
android接入高德路线规划,不会显示路线拥堵情况。
·
android接入高德路线规划,不会显示路线拥堵情况。
//初始化路线规划,监听回调数据
try {
if (routeSearchV2 == null) {
routeSearchV2 = new RouteSearchV2(getActivity());
}
routeSearchV2.setRouteSearchListener(this);
} catch (AMapException e) {
e.printStackTrace();
}
RouteSearchV2.FromAndTo fromAndTo1 = new RouteSearchV2.FromAndTo(startLatLon, latLonPoint);
RouteSearchV2.DriveRouteQuery query1 = new RouteSearchV2.DriveRouteQuery(fromAndTo1, RouteSearchV2.DrivingStrategy.DEFAULT, null,
null, "");// 第一个参数表示路径规划的起点和终点,第二个参数表示驾车模式,第三个参数表示途经点,第四个参数表示避让区域,第五个参数表示避让道路
主要就是这个方法,官方API没有更新,找了两天才解决,还是另一个大佬给解决的。心塞
//显示扩展字段
query1.setShowFields(RouteSearchV2.ShowFields.POLINE | RouteSearchV2.ShowFields.CITIES |
RouteSearchV2.ShowFields.COST | RouteSearchV2.ShowFields.NAVI | RouteSearchV2.ShowFields.TMCS);
// 异步路径规划驾车模式查询
routeSearchV2.calculateDriveRouteAsyn(query1);
// 在回调中这么写
@Override
public void onDriveRouteSearched(DriveRouteResultV2 driveRouteResultV2, int errorCode) {
if (drivingRouteOverlay != null)
drivingRouteOverlay.removeFromMap();
if (errorCode == AMapException.CODE_AMAP_SUCCESS) {
if (driveRouteResultV2 != null && driveRouteResultV2.getPaths() != null) {
if (driveRouteResultV2.getPaths().size() > 0) {
mDriveRouteResultV2 = driveRouteResultV2;
final DrivePathV2 drivePath = driveRouteResultV2.getPaths()
.get(0);
drivingRouteOverlay = new DrivingRouteOverlay(
getContext(), aMap, drivePath,
mDriveRouteResultV2.getStartPos(),
mDriveRouteResultV2.getTargetPos(), null);
drivingRouteOverlay.setRouteWidth(20);
drivingRouteOverlay.setNodeIconVisibility(false);//设置节点marker是否显示
drivingRouteOverlay.setIsColorfulline(true);//是否用颜色展示交通拥堵情况,默认true
drivingRouteOverlay.addToMap();
drivingRouteOverlay.zoomToSpan();
}
}
}
}
记录一下android分享微信朋友圈
转载 https://www.xp.cn/b.php/109117.html
更多推荐
所有评论(0)
您需要登录才能发言
查看更多评论