代码
const map = new BMap.Map('map');
map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);
var type = '';
type = TRANSIT_ROUTE; // 公交检索
type = DRIVING_ROUTE; // 驾车检索
type = LOCAL_SEARCH; // 本地检索

// 创建检索控件
var searchControl = new BMapLib.SearchControl({
  container: 'searchBox', // 存放控件的容器
  map: map, // 关联地图对象
  type: type, // 检索类型
});

document.getElementById('selectType').onchange = function () {
  searchControl.setType(this.value);
};
预览