高德地图 android 开发 路线规划 自定义 修改线路颜色和宽度
2016-08-20 16:04
711 查看
public class MyDrivingRouteOverlay extends DrivingRouteOverlay {
public int color;// 路线颜色
public float lineWidth;// 路线宽度
public MyDrivingRouteOverlay(Context context, AMap amap, DrivePath drivepath, LatLonPoint latlonpoint,
LatLonPoint latlonpoint1) {
super(context, amap, drivepath, latlonpoint, latlonpoint1);
}
public MyDrivingRouteOverlay(Context context, AMap amap, DrivePath drivepath, LatLonPoint latlonpoint,
LatLonPoint latlonpoint1, List<LatLonPoint> list) {
super(context, amap, drivepath, latlonpoint, latlonpoint1, list);
}
/* 一个工具方法,修改颜色和宽度 */
public void setView(int color, float width) {
this.color = color;
lineWidth = width;
}
@SuppressWarnings("static-access")
@Override
protected void addStartAndEndMarker() {
BitmapDescriptorFactory bdf = new BitmapDescriptorFactory();
BitmapDescriptor startbd = bdf.fromResource(R.drawable.factory);
BitmapDescriptor endbd = bdf.fromResource(R.drawable.project);
startMarker = mAMap.addMarker((new MarkerOptions()).position(startPoint).icon(startbd).title("\u8D77\u70B9"));
endMarker = mAMap.addMarker((new MarkerOptions()).position(endPoint).icon(endbd).title("\u7EC8\u70B9"));
}
public void setMarkerIcon() {
Marker startmarker = this.startMarker;
startmarker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.factory));
Marker endmarker = this.endMarker;
endmarker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.project));
}
@Override
protected float getRouteWidth() {
// TODO Auto-generated method stub
return lineWidth;
}
@Override
protected int getDriveColor() {
// TODO Auto-generated method stub
return color;
}
}
在自定义的监听器里面用
public class GDRouteSearchListener implements OnRouteSearchListener {
private Context mContext;
private AMap mAMap;
private BusRouteResult mBusRouteResult;
private DriveRouteResult mDriveRouteResult;
private int direction;
//direction 是我个人用来标注去程返程的一个参数 用来判断 规划的线路是去程还是返程
public GDRouteSearchListener(Context context, AMap aMap, int direction) {
this.mContext = context;
this.mAMap = aMap;
this.direction = direction;
}
public GDRouteSearchListener(Context context, AMap aMap) {
this.mContext = context;
this.mAMap = aMap;
}
/**
* 公交换乘路径规划结果的回调方法。
*/
@Override
public void onBusRouteSearched(BusRouteResult result, int errorCode) {
}
/**
* 驾车路径规划结果的回调方法。
*/
@Override
public void onDriveRouteSearched(DriveRouteResult result, int errorCode) {
if (1000 == errorCode) {
if (null != result) {
if (null != result.getPaths()) {
if (result.getPaths().size() > 0) {
mDriveRouteResult = result;
DrivePath drivePath = mDriveRouteResult.getPaths().get(0);
;
if (direction == 1 || direction == 0) {
MyDrivingRouteOverlay myDrivingRouteOverlay = new MyDrivingRouteOverlay(mContext, mAMap,
drivePath, mDriveRouteResult.getStartPos(), mDriveRouteResult.getTargetPos());
myDrivingRouteOverlay.setView(0xff0c91f8, 10);
myDrivingRouteOverlay.setNodeIconVisibility(false);// 路段节点图标控制显示接口。
myDrivingRouteOverlay.removeFromMap();// 去掉DriveLineOverlay上所有的Marker。
myDrivingRouteOverlay.addToMap();// 绘制节点和线路
myDrivingRouteOverlay.zoomToSpan();
} else {
MyDrivingRouteOverlaytwo myDrivingRouteOverlay = new MyDrivingRouteOverlaytwo(mContext,
mAMap, drivePath, mDriveRouteResult.getStartPos(),
mDriveRouteResult.getTargetPos());
myDrivingRouteOverlay.setView(0xff33cc60, 10);
myDrivingRouteOverlay.setNodeIconVisibility(false);
myDrivingRouteOverlay.removeFromMap();
myDrivingRouteOverlay.addToMap();
myDrivingRouteOverlay.zoomToSpan();
}
// DrivingRouteOverlay mDrivingRouteOverlay = new
// DrivingRouteOverlay(mContext, mAMap, drivePath,
// mDriveRouteResult.getStartPos(),
// mDriveRouteResult.getTargetPos());
// // 路段节点图标控制显示接口。
// mDrivingRouteOverlay.setNodeIconVisibility(false);
// mDrivingRouteOverlay.removeFromMap();
// mDrivingRouteOverlay.addToMap();
// mDrivingRouteOverlay.zoomToSpan();
}
}
}
}
}
/**
* 步行路径规划结果的回调方法。
*/
@Override
public void onWalkRouteSearched(WalkRouteResult arg0, int arg1) {
}
}
在主函数里面掉用
private RouteSearch mRouteSearch;
private GDRouteSearchListener mGdRouteSearchListener;
mRouteSearch = new RouteSearch(this);
mGdRouteSearchListener = new GDRouteSearchListener(CarMapActivity.this, amp, direction);
mRouteSearch.setRouteSearchListener(mGdRouteSearchListener);
// 第一个参数表示路径规划的起点和终点,第二个参数表示驾车模式,第三个参数表示途经点,第四个参数表示避让区域,第五个参数表示避让道路
DriveRouteQuery query = new DriveRouteQuery(fromAndTo, RouteSearch.DrivingDefault, null, null, "");
mRouteSearch.calculateDriveRouteAsyn(query);// 异步路径规划驾车模式查询
public int color;// 路线颜色
public float lineWidth;// 路线宽度
public MyDrivingRouteOverlay(Context context, AMap amap, DrivePath drivepath, LatLonPoint latlonpoint,
LatLonPoint latlonpoint1) {
super(context, amap, drivepath, latlonpoint, latlonpoint1);
}
public MyDrivingRouteOverlay(Context context, AMap amap, DrivePath drivepath, LatLonPoint latlonpoint,
LatLonPoint latlonpoint1, List<LatLonPoint> list) {
super(context, amap, drivepath, latlonpoint, latlonpoint1, list);
}
/* 一个工具方法,修改颜色和宽度 */
public void setView(int color, float width) {
this.color = color;
lineWidth = width;
}
@SuppressWarnings("static-access")
@Override
protected void addStartAndEndMarker() {
BitmapDescriptorFactory bdf = new BitmapDescriptorFactory();
BitmapDescriptor startbd = bdf.fromResource(R.drawable.factory);
BitmapDescriptor endbd = bdf.fromResource(R.drawable.project);
startMarker = mAMap.addMarker((new MarkerOptions()).position(startPoint).icon(startbd).title("\u8D77\u70B9"));
endMarker = mAMap.addMarker((new MarkerOptions()).position(endPoint).icon(endbd).title("\u7EC8\u70B9"));
}
public void setMarkerIcon() {
Marker startmarker = this.startMarker;
startmarker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.factory));
Marker endmarker = this.endMarker;
endmarker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.project));
}
@Override
protected float getRouteWidth() {
// TODO Auto-generated method stub
return lineWidth;
}
@Override
protected int getDriveColor() {
// TODO Auto-generated method stub
return color;
}
}
在自定义的监听器里面用
public class GDRouteSearchListener implements OnRouteSearchListener {
private Context mContext;
private AMap mAMap;
private BusRouteResult mBusRouteResult;
private DriveRouteResult mDriveRouteResult;
private int direction;
//direction 是我个人用来标注去程返程的一个参数 用来判断 规划的线路是去程还是返程
public GDRouteSearchListener(Context context, AMap aMap, int direction) {
this.mContext = context;
this.mAMap = aMap;
this.direction = direction;
}
public GDRouteSearchListener(Context context, AMap aMap) {
this.mContext = context;
this.mAMap = aMap;
}
/**
* 公交换乘路径规划结果的回调方法。
*/
@Override
public void onBusRouteSearched(BusRouteResult result, int errorCode) {
}
/**
* 驾车路径规划结果的回调方法。
*/
@Override
public void onDriveRouteSearched(DriveRouteResult result, int errorCode) {
if (1000 == errorCode) {
if (null != result) {
if (null != result.getPaths()) {
if (result.getPaths().size() > 0) {
mDriveRouteResult = result;
DrivePath drivePath = mDriveRouteResult.getPaths().get(0);
;
if (direction == 1 || direction == 0) {
MyDrivingRouteOverlay myDrivingRouteOverlay = new MyDrivingRouteOverlay(mContext, mAMap,
drivePath, mDriveRouteResult.getStartPos(), mDriveRouteResult.getTargetPos());
myDrivingRouteOverlay.setView(0xff0c91f8, 10);
myDrivingRouteOverlay.setNodeIconVisibility(false);// 路段节点图标控制显示接口。
myDrivingRouteOverlay.removeFromMap();// 去掉DriveLineOverlay上所有的Marker。
myDrivingRouteOverlay.addToMap();// 绘制节点和线路
myDrivingRouteOverlay.zoomToSpan();
} else {
MyDrivingRouteOverlaytwo myDrivingRouteOverlay = new MyDrivingRouteOverlaytwo(mContext,
mAMap, drivePath, mDriveRouteResult.getStartPos(),
mDriveRouteResult.getTargetPos());
myDrivingRouteOverlay.setView(0xff33cc60, 10);
myDrivingRouteOverlay.setNodeIconVisibility(false);
myDrivingRouteOverlay.removeFromMap();
myDrivingRouteOverlay.addToMap();
myDrivingRouteOverlay.zoomToSpan();
}
// DrivingRouteOverlay mDrivingRouteOverlay = new
// DrivingRouteOverlay(mContext, mAMap, drivePath,
// mDriveRouteResult.getStartPos(),
// mDriveRouteResult.getTargetPos());
// // 路段节点图标控制显示接口。
// mDrivingRouteOverlay.setNodeIconVisibility(false);
// mDrivingRouteOverlay.removeFromMap();
// mDrivingRouteOverlay.addToMap();
// mDrivingRouteOverlay.zoomToSpan();
}
}
}
}
}
/**
* 步行路径规划结果的回调方法。
*/
@Override
public void onWalkRouteSearched(WalkRouteResult arg0, int arg1) {
}
}
在主函数里面掉用
private RouteSearch mRouteSearch;
private GDRouteSearchListener mGdRouteSearchListener;
mRouteSearch = new RouteSearch(this);
mGdRouteSearchListener = new GDRouteSearchListener(CarMapActivity.this, amp, direction);
mRouteSearch.setRouteSearchListener(mGdRouteSearchListener);
// 第一个参数表示路径规划的起点和终点,第二个参数表示驾车模式,第三个参数表示途经点,第四个参数表示避让区域,第五个参数表示避让道路
DriveRouteQuery query = new DriveRouteQuery(fromAndTo, RouteSearch.DrivingDefault, null, null, "");
mRouteSearch.calculateDriveRouteAsyn(query);// 异步路径规划驾车模式查询
相关文章推荐
- android开发游记:百度地图SDK路线规划和自定义地图UI覆盖物及弹出窗
- 【Android】安卓开发实战之自定义分隔线条的长度、宽度、颜色
- 高德地图Android自定义路线规划的简单实现
- 【android开发】 修改控件Spinner内容的字体大小 颜色等属性
- (android地图开发) 高德地图自定义标题栏
- 安卓高德地图开发(四)——自定义线路规划(根据地点的经纬度规划线路)
- Android底部菜单栏、Android沉浸式状态栏(顶部状态栏修改颜色)、自定义标题栏
- Android百度地图开发05之公交信息检索 + 路线规划
- Android软件开发学习路线规划
- 【Android开发日记】TextView超链接启动 Activity,取消下划线自定义颜色
- 安卓高德地图开发自定义线路规划(按着自己定义的经纬度规划线路)
- Android开发中颜色的自定义方法
- android开发学习笔记——自定义布局的dialog宽度的问题
- Android版本百度地图开发(三)——路线规划
- 【android开发】 修改控件Spinner内容的字体大小 颜色等属性
- (android地图开发) 高德地图添加自定义菜单栏
- VS MONO Android开发控件悬浮显示提醒 自定义背景颜色、字体、数字颜色、摆放位置
- Android版本百度地图开发(三)——路线规划
- IOS开发—无需自定义,修改tabbar背景颜色
- Android开发中颜色的自定义方法