百度地图搜索功能的实现--new BMap.LocalSearch

          let local = new BMap.LocalSearch(map, {
              renderOptions: {
                  map: map,
              },
              onSearchComplete: (res) => {
                 if (local.getResults() != undefined && local.getResults().Cr.length!= 0) {                      
                         map.clearOverlays(); //清除标注
                         this.addMapMark();  //添加已存在的其他标注--(根据自己情况保留删除)
                  } else if (local.getResults().Cr.length == 0) {
                         this.$alert("请您精确搜索内容", {
                             confirmButtonText: "确定",
                         });
                  } else {
                        this.$alert("未找到搜索结果", {
                             confirmButtonText: "确定",
                        });
                  }
              },
          });
          local.search(this.where);

实现效果: