Android高德地图实现路径规划

需要在官方文档下载

libs,res,overlay,util


需要接口     RouteSearch.OnRouteSearchListener, GeocodeSearch.OnGeocodeSearchListener


//显示地图

sourceSets{

main{

jniLibs.srcDirs = ['libs']

}

}

这重写的的方法onDriveRouteSearched里

//清除所有地图标识点

aMap.clear();

if (errorCode == AMapException.CODE_AMAP_SUCCESS) {

if (result != null && result.getPaths() != null) {

if (result.getPaths().size() > 0) {

DriveRouteResult mDriveRouteResult = result;

final DrivePath drivePath = mDriveRouteResult.getPaths()

.get(0);

DrivingRouteOverlay drivingRouteOverlay = new DrivingRouteOverlay(

MainActivity.this, aMap, drivePath,

mDriveRouteResult.getStartPos(),

mDriveRouteResult.getTargetPos(), null);

drivingRouteOverlay.setNodeIconVisibility(false);//设置节点marker是否显示

drivingRouteOverlay.setIsColorfulline(true);//是否用颜色展示交通拥堵情况,默认true

drivingRouteOverlay.removeFromMap();

drivingRouteOverlay.addToMap();

drivingRouteOverlay.zoomToSpan();

} else if (result != null && result.getPaths() == null) {

ToastUtil.show(MainActivity.this, R.string.no_result);

}

} else {

ToastUtil.show(MainActivity.this, R.string.no_result);

}

} else {

ToastUtil.showerror(this.getApplicationContext(), errorCode);

}

在重写方法onGeocodeSearched里

GeocodeAddress geocodeAddress = geocodeResult.getGeocodeAddressList().get(0);

//经度

double longitude = geocodeAddress.getLatLonPoint().getLongitude();

//纬度

double latitude = geocodeAddress.getLatLonPoint().getLatitude();

Log.d("MainActivity", longitude + "..." + latitude);

//驾车路线规划

routeSearch = new RouteSearch(MainActivity.this);

routeSearch.setRouteSearchListener(MainActivity.this);

// fromAndTo包含路径规划的起点和终点,drivingMode表示驾车模式

// 第三个参数表示途经点(最多支持16个),第四个参数表示避让区域(最多支持32个),第五个参数表示避让道路

RouteSearch.FromAndTo fromAndTo = new RouteSearch.FromAndTo(new LatLonPoint(40.1767200000, 116.16502000000), new LatLonPoint(latitude, longitude));

RouteSearch.DriveRouteQuery query = new RouteSearch.DriveRouteQuery(fromAndTo, RouteSearch.BUS_DEFAULT, null, null, "");

routeSearch.calculateDriveRouteAsyn(query);


在点击按钮里

//内容地址的坐标查询

GeocodeSearch geocodeSearch = new GeocodeSearch(MainActivity.this);

geocodeSearch.setOnGeocodeSearchListener(MainActivity.this);

//城市编码

GeocodeQuery query = new GeocodeQuery(mEditText.getText().toString(), "010");

geocodeSearch.getFromLocationNameAsyn(query);

你可能感兴趣的:(Android高德地图实现路径规划)