APP ID 1106841746
APP KEY afToyUkscz832oz9
地图路径规划
1, // 定义 Marker 点击事件监听
AMap.OnMarkerClickListener markerClickListener = new AMap.OnMarkerClickListener() {
// marker 对象被点击时回调的接口
// 返回 true 则表示接口已响应事件,否则返回false
@Override
public boolean onMarkerClick(Marker marker) {
lujingguihua(marker);
return true;
}
};
// 绑定 Marker 被点击事件
aMap.setOnMarkerClickListener(markerClickListener);
2, private void lujingguihua(Marker marker){
RouteSearch routeSearch = new RouteSearch(MainActivity.this);
routeSearch.setRouteSearchListener(listener);
//TODO 难点1
// fromAndTo包含路径规划的起点和终点,drivingMode表示驾车模式
// 第三个参数表示途经点(最多支持16个),第四个参数表示避让区域(最多支持32个),第五个参数表示避让道路
//获取自己的坐标系
Location myLocation = aMap.getMyLocation();
LatLonPoint startPoint = new LatLonPoint(myLocation.getLatitude(),myLocation.getLongitude());
//目的地坐标系
LatLng position = marker.getPosition();
LatLonPoint endPoint = new LatLonPoint(position.latitude,position.longitude);
RouteSearch.FromAndTo fat = new RouteSearch.FromAndTo(startPoint,endPoint);
RouteSearch.DriveRouteQuery query = new RouteSearch.DriveRouteQuery(fat, 0, null, null, "");
routeSearch.calculateDriveRouteAsyn(query);//发起请求
}
RouteSearch.OnRouteSearchListener listener = new RouteSearch.OnRouteSearchListener() {
@Override
public void onBusRouteSearched(BusRouteResult busRouteResult, int i) {
}
@Override
public void onDriveRouteSearched(DriveRouteResult result, int errorCode) {
//TODO 难点2
//展示算路的数据
aMap.clear();// 清理地图上的所有覆盖物
if (errorCode == AMapException.CODE_AMAP_SUCCESS) {
if (result != null && result.getPaths() != null) {
if (result.getPaths().size() > 0) {
final DrivePath drivePath = result.getPaths()
.get(0);
DrivingRouteOverlay drivingRouteOverlay = new DrivingRouteOverlay(
MainActivity.this, aMap, drivePath,
result.getStartPos(),
result.getTargetPos(), null);
drivingRouteOverlay.setNodeIconVisibility(false);//设置节点marker是否显示
drivingRouteOverlay.setIsColorfulline(true);//是否用颜色展示交通拥堵情况,默认true
drivingRouteOverlay.removeFromMap();
drivingRouteOverlay.addToMap();
drivingRouteOverlay.zoomToSpan();
}
}
}
}
@Override
public void onWalkRouteSearched(WalkRouteResult walkRouteResult, int i) {
}
@Override
public void onRideRouteSearched(RideRouteResult rideRouteResult, int i) {
}
};
3,加入一个文件夹
holder.rb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
biao++;
if(biao>2){
Toast.makeText(context,"你已选中两个地址",Toast.LENGTH_SHORT).show();
holder.rb.setChecked(false);
}else{
list1.add(list.get(position));
}
}
});