室内路线规划
1、创建路线规划检索实例
mSearch = RoutePlanSearch.newInstance();
2、创建路线规划检索监听器
mSearch.setOnGetRoutePlanResultListener(new OnGetRoutePlanResultListener() {
@Override
public void onGetWalkingRouteResult(WalkingRouteResult walkingRouteResult) {
}
@Override
public void onGetTransitRouteResult(TransitRouteResult transitRouteResult) {
}
@Override
public void onGetMassTransitRouteResult(MassTransitRouteResult massTransitRouteResult) {
}
@Override
public void onGetDrivingRouteResult(DrivingRouteResult drivingRouteResult) {
}
@Override
public void onGetIndoorRouteResult(IndoorRouteResult indoorRouteResult) {
if (indoorRouteResult.error == SearchResult.ERRORNO.NO_ERROR) {
IndoorRouteOverlay overlay = new IndoorRouteOverlay(mBaiduMap);
mIndoorRouteline = indoorRouteResult.getRouteLines().get(0);
nodeIndex = -1;
mBtnPre.setVisibility(View.VISIBLE);
mBtnNext.setVisibility(View.VISIBLE);
overlay.setData(indoorRouteResult.getRouteLines().get(0));
overlay.addToMap();
overlay.zoomToSpan();
}
}
@Override
public void onGetBikingRouteResult(BikingRouteResult bikingRouteResult) {
}
});
3、发起室内路线规划
indoorRoutePlane = (Button)findViewById(R.id.indoorRoutePlane);
indoorRoutePlane.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
// 发起室内路线规划检索
//设置起点终点
IndoorPlanNode startNode = new IndoorPlanNode(new LatLng(39.917380, 116.37978), "F1");
IndoorPlanNode endNode = new IndoorPlanNode(new LatLng(39.917239, 116.37955), "F6");
IndoorRoutePlanOption irpo = new IndoorRoutePlanOption().from(startNode).to(endNode);
mSearch.walkingIndoorSearch(irpo);
}
});
4、节点浏览示例
public void nodeClick(View v) {
if (mBaiduMap.isBaseIndoorMapMode()) {
LatLng nodeLocation = null;
String nodeTitle = null;
IndoorRouteLine.IndoorRouteStep step = null;
if (mIndoorRouteline == null || mIndoorRouteline.getAllStep() == null) {
return;
}
if (nodeIndex == -1 && v.getId() == R.id.pre) {
return;
}
// 设置节点索引
if (v.getId() == R.id.next) {
if (nodeIndex < mIndoorRouteline.getAllStep().size() - 1) {
nodeIndex++;
} else {
return;
}
} else if (v.getId() == R.id.pre) {
if (nodeIndex > 0) {
nodeIndex--;
} else {
return;
}
}
// 获取节结果信息
step = mIndoorRouteline.getAllStep().get(nodeIndex);
nodeLocation = step.getEntrace().getLocation();
nodeTitle = step.getInstructions();
if (nodeLocation == null || nodeTitle == null) {
return;
}
// 移动节点至中心
mBaiduMap.setMapStatus(MapStatusUpdateFactory.newLatLng(nodeLocation));
// show popup
popupText = new TextView(IndoorSearchActivity.this);
popupText.setBackgroundResource(R.drawable.popup);
popupText.setTextColor(0xFF000000);
popupText.setText(step.getFloorId() + ":" + nodeTitle);
mBaiduMap.showInfoWindow(new InfoWindow(popupText, nodeLocation, 0));
// 让楼层对应变化
mBaiduMap.switchBaseIndoorMapFloor(step.getFloorId(), mMapBaseIndoorMapInfo.getID());
// mFloorListAdapter.setSelectedPostion();
mFloorListAdapter.notifyDataSetInvalidated();
}else{
Toast.makeText(IndoorSearchActivity.this,"请打开室内图或将室内图移入屏幕内",Toast.LENGTH_SHORT).show();
}
}
5、运行效果如图:
6、左右按钮的点击效果,如图: