输入某一位置查询附近(如3公里)的客户信息,查询后根据输入的位置(起始位置)和部分的客户的地址(客户地址可选)规划出最短的路径;
希望得到:
1:解决思路
2:百度、高德是否有这样的接口
1.解决思路:就像你说的那样就行,定位到自己的位置,输入终点,计算路线就好
2.高德地图可以
public void calculateRoute(View view) {
if (endLatlng != null) {
mLoadingDlg = new ProgressDialog(PoiKeywordSearchActivity.this);
mLoadingDlg.setTitle("计算路线");
mLoadingDlg.setMessage("请稍后,正在计算多条路线...");
mLoadingDlg.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode,
KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
mLoadingDlg.cancel();
finish();
}
return false;
}
});
mLoadingDlg.show();
startList.add(startLatlng);
endList.add(endLatlng);
aMapNavi.calculateDriveRoute(startList, endList, null,
PathPlanningStrategy.DRIVING_MULTIPLE_ROUTES);
} else {
Toast.makeText(this, "请先选择地点", Toast.LENGTH_LONG).show();
}
}
希望楼主采纳,谢谢。
需求:起点,终点,规划路线
解决方式:调用百度地图或者高德地图客户端,实现驾车,步行,公交路线规划。这样,可以让用户自己选择时间最短,少拥堵等条件下的路程导航
个人实现过调用路线规划的导航,代码如下:
public class SelectMapNaviDialog extends AlertDialog implements
android.view.View.OnClickListener {
private View rootView;
private Context context;
private ImageView mapNavi_iv, aMapNavi_iv, close_iv;
private double tagLatitude, tagLongtitude;
private String tagAdres;
public SelectMapNaviDialog(Context context, double tagLatitude,
double tagLongtitude, String tagAdres) {
super(context);
this.context = context;
this.tagAdres = tagAdres;
this.tagLatitude = tagLatitude;
this.tagLongtitude = tagLongtitude;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().getAttributes().gravity = Gravity.CENTER;
this.getWindow().getAttributes().width = (BaseApplication.getContext()
.getWidthPixels() / 5) * 4;
this.setCanceledOnTouchOutside(false);
initView();
}
private void initView() {
rootView = View.inflate(context, R.layout.dialog_select_navi, null);
mapNavi_iv = (ImageView) rootView
.findViewById(R.id.select_baidu_navi_iv);
close_iv = (ImageView) rootView
.findViewById(R.id.select_navi_to_cacle_iv);
aMapNavi_iv = (ImageView) rootView
.findViewById(R.id.select_amap_navi_iv);
close_iv.setOnClickListener(this);
mapNavi_iv.setOnClickListener(this);
aMapNavi_iv.setOnClickListener(this);
this.setContentView(rootView);
}
protected void openBaiduNavi() {
LatLng startLatLng = null, endLatLng = null;
startLatLng = new LatLng(BaseApplication.getContext().latitude,
BaseApplication.getContext().longtitude);
endLatLng = new LatLng(tagLatitude, tagLongtitude);
RouteParaOption routeParaOption = new RouteParaOption();
routeParaOption.startPoint(startLatLng);
routeParaOption.endPoint(endLatLng);
try {
BaiduMapRoutePlan
.openBaiduMapDrivingRoute(routeParaOption, context);
} catch (BaiduMapAppNotSupportNaviException e) {
e.printStackTrace();
showToast("请安装百度地图");
}
}
public void showToast(String s){
MyUtils.showToast(s);
}
protected void openAmapNavi() {
// 先转换到高德地图的坐标
com.amap.api.maps.model.LatLng tagLatLng = converter(new com.amap.api.maps.model.LatLng(
tagLatitude, tagLongtitude));
com.amap.api.maps.model.LatLng startLatLng = converter(new com.amap.api.maps.model.LatLng(
BaseApplication.getContext().latitude,
BaseApplication.getContext().longtitude));
try {
RoutePara routePara = new RoutePara();
routePara.setStartPoint(startLatLng);
routePara.setEndPoint(tagLatLng);
routePara.setEndName(tagAdres);
routePara.setStartName(BaseApplication.getContext().address);
AMapUtils.openAMapDrivingRoute(routePara,
BaseApplication.getContext());
} catch (com.amap.api.maps.AMapException e) {
e.printStackTrace();
showToast("请安装高德地图");
/* // 如果没安装会进入异常,调起下载页面
// AMapUtils.getLatestAMapApp(getApplicationContext());
*/ } catch (Exception e) {
e.printStackTrace();
}
}
public com.amap.api.maps.model.LatLng converter(
com.amap.api.maps.model.LatLng sourceLatLng) {
CoordinateConverter converter = new CoordinateConverter(context);
converter.from(CoordType.BAIDU);
converter.coord(sourceLatLng);
return converter.convert();
}
@Override
public void onClick(View view) {
LogController.i("selectNavi","startLatitude "+BaseApplication.getContext().latitude+" startLongtitude " +BaseApplication.getContext().longtitude+" startAdress "+BaseApplication.getContext().address+" tagLatitude"+tagLatitude+" tagLongtitude "+tagLongtitude+" tagAdress "+tagAdres);
switch (view.getId()) {
case R.id.select_baidu_navi_iv:
openBaiduNavi();
this.dismiss();
break;
case R.id.select_amap_navi_iv:
openAmapNavi();
this.dismiss();
break;
case R.id.select_navi_to_cacle_iv:
this.dismiss();
break;
default:
break;
}
}
}
若是还有地图其他需求,可以参考 http://blog.csdn.net/hexingen/article/details/51838399