是否执行成功其中对于算路的节点,现在有了一个新的规则,可见BNRoutePlanNode
取文档的释义如下:
publicBNRoutePlanNode(doublelongitude,
doublelatitude,
java.lang.Stringname,
java.lang.Stringdescription,
BNRoutePlanNode.CoordinateTypecoType)
算路节点构造方法.
参数:longitude- 经度latitude- 纬度name- 算路节点名description- 算路节点地址描述coType- 坐标类型,参考CoordinateType
可见现在对于算路节点的坐标类型有了一个标准,也即
百度墨卡托坐标
国测局坐标
GPS坐标
坐标类型必须为以上三种,否则如果不指定或者默认匹配不到这三种坐标类型则都会导致算路失败。
但是百度定位SDK的坐标系一般用的是bd09ll类型,这时候就需要用到类型转换,在5.3版本之前可以有另一种方法来转换的,但是5.3版本就取消了,于是6.0.5之后就有了这个函数来做转换,如下
public static BDLocation getBDLocationInCoorType(BDLocation src,
java.lang.String transferType)
根据设定的转换坐标系类型得到相应坐标系下的BDLocation
参数:
BDLocation - src 原始BDLocation
transferType - BDLocation.BDLOCATION_GCJ02_TO_BD09/BDLOCATION_GCJ02_TO_BD09LL/BDLOCATION_BD09_TO_GCJ02/ BDLOCATION_BD09LL_TO_GCJ02
用这个就可以直接将百度定位和地图获取的BDLocation转换成可以直接使用的导航参数。
以此希望可以帮到尚不明白如何转换的同学!
部分代码如下:
// 发起算路
private void startCalcRoute(int calcMode) {
// 显示加载对话框
DialogUtil.getInstance().showProgressDialog(mActivity);
if (mBdLocation == null) {
Toast.makeText(this, getString(R.string.map_location_failed), Toast.LENGTH_LONG).show();
// 取消加载对话框
DialogUtil.getInstance().dismissProgressDialog();
return;
}
if (calcMode == 0)
calcMode = BaiduNaviManager.RoutePlanPreference.ROUTE_PLAN_MOD_AVOID_TAFFICJAM;
double sX = 0, sY = 0, eX = 0, eY = 0;
sX = LocationClient.getBDLocationInCoorType(mBdLocation, BDLocation.BDLOCATION_BD09LL_TO_GCJ02).getLatitude();
sY = LocationClient.getBDLocationInCoorType(mBdLocation, BDLocation.BDLOCATION_BD09LL_TO_GCJ02).getLongitude();
BNRoutePlanNode startNode = new BNRoutePlanNode(sY, sX, "我的位置", "我的位置");BDLocation bd = new BDLocation();
bd.setLatitude(destLat);
bd.setLongitude(destLng);
eX = LocationClient.getBDLocationInCoorType(bd, BDLocation.BDLOCATION_BD09LL_TO_GCJ02).getLatitude();
eY = LocationClient.getBDLocationInCoorType(bd, BDLocation.BDLOCATION_BD09LL_TO_GCJ02).getLongitude();
BNRoutePlanNode endNode = new BNRoutePlanNode(eY, eX, strDestAddress, strDestAddress);
ArrayList nodeList = new ArrayList(2);
nodeList.add(startNode);
nodeList.add(endNode);
BaiduNaviManager.getInstance().launchNavigator(mActivity, nodeList, calcMode, true,
new MapRoutePlanListener(startNode));
}