美文网首页
vue 智能检索提示--手动定位

vue 智能检索提示--手动定位

作者: 冰落寞成 | 来源:发表于2021-07-01 09:49 被阅读0次

手动定位,输入关键词,实现智能提示 要实现的效果

image.png

vue 引入vue-baidu-map 使用npm 引入

npm install vue-baidu-map --save

在vue 里面引入地图

<baidu-map
          :center="center"
          :zoom="zoom"
          class="map"
          scroll-wheel-zoom
          @ready="mapReady"

          id="allmap"
        >
         
        </baidu-map>

在vue 里使用自动检索

el-form-item label="手动定位" class="mgb0">
            <el-autocomplete
              v-model="searchA"
              ref="autocomplete"
              placeholder="请输入内容"
              :fetch-suggestions="querySearchAsync"
              @select="manualSearch"
            ></el-autocomplete>
          </el-form-item>

js 代码

变量定义

data(){
return{
 point: null,
      center: { lng: 116.404, lat: 39.915 },
      BMap: null,
      map: null,
      searchA: null,
      manualPoint: null,
      ac: null,
}

map ready 代码

 /**
     * 重新定位地图
     */
    mapReady ({ BMap, map }) {
      let point = new BMap.Point(this.center.lng, this.center.lat) // 默认北京
      map.centerAndZoom(point, this.zoom)
      this.BMap = BMap
      this.map = map

        bGeolocation()
    
      function bGeolocation (that) {
        geolocation.getCurrentPosition(function (r) {
          if (this.getStatus() === BMAP_STATUS_SUCCESS) {
            let mk = new BMap.Marker(r.point)
            that.manualPoint = r.point
            map.addOverlay(mk)
            map.panTo(r.point)
            // 坐标转换完之后的回调函数
            geoc.getLocation(r.point, function (rs) {
              that.address = rs.address
            })
          } else {
            alert('failed' + this.getStatus())
          }
        }, { enableHighAccuracy: true })
      }

      this.ac = new BMap.Autocomplete( // 建立一个自动完成的对象
        {
          input: this.$refs.autocomplete.$el.querySelector('input'),
          location: map,
          onSearchComplete: (e) => {
            this.autoResult = []
            let length = e.getNumPois()
            for (let i = 0; i < length; i++) {
              let json = {
                id: i,
                value: e.getPoi(i).business
              }
              console.log(e.getPoi(i))
              this.autoResult.push(json)
            }
          }
        })
    },

input 框 提示

 /**
     * 智能检索提示
     */
    querySearchAsync (queryString, cb) {
      cb(this.autoResult)
    },

点击提示框检索关键字

 /**
     * 手动定位
     */
    manualSearch (e) {
      this.map.clearOverlays()

      var local = new this.BMap.LocalSearch(this.map, {
        onSearchComplete: (results) => {
          let length = results.getNumPois()
          this.map.centerAndZoom(results.getPoi(0).point, this.zoom * 10)
          this.address = results.getPoi(0).address
          for (let i = 0; i < length; i++) {
            let point = results.getPoi(i).point
            this.map.addOverlay(new this.BMap.Marker(point)) // 添加标注
          }
        }
      })
      local.search(e.value)
    },

相关文章

  • vue 智能检索提示--手动定位

    手动定位,输入关键词,实现智能提示 要实现的效果 vue 引入vue-baidu-map 使用npm 引入 在v...

  • 百度地图

    官网 成为开发者 申请秘钥(ak) 部署 手动部署 自动部署 地图 定位 导航 室内图 地图覆盖物 POI检索 地...

  • VSCode 相关设置 - 代码段、插件

    VSCode 相关设置 - 代码段、插件 一、插件类 1. 【vue】代码提示插件 【Vetur】可以智能提示 v...

  • Atom 插件

    安装失败 手动安装 安装完后运行提示缺少 文件 插件 ** docblockr**智能代码注释,让注释更有规范 *...

  • 2018-11-06文献检索与利用作业

    人工智能 检索词:人工智能 数据库:中国学术期刊全文数据库 检索步骤和过滤筛选分析过程 检索:人工智能,检索到95...

  • 基于本体的智能信息检索系统

    引入人工智能技术,具有一定程度的智能特征的信息检索系统,就是智能信息检索系统。智能信息检索系统按照研究的侧重点不...

  • VS Code 新建vue文件初始化模板

    在使用VS Code进行vue开发的时候,我们可以充分现有的vue插件进行智能提示,可以提高开发效率,但是,在VS...

  • 百度地图vue-baidu-map自动定位,鼠标选点并进行逆解析

    百度地图vue-baidu-map自动定位,鼠标选点并进行逆解析,地区检索,配合使用使用案列以及解决方案 效果图如...

  • Vue脚手架

    1. Vue 脚手架的基本用法 在没有Vue脚手架的时候,我们需要手动搭建webpack项目、手动去配置vue,现...

  • HTML/CSS 07-定位属性/锚点/透明

    一、position定位 1.position定位属性:检索对象的定位方式 语法: position: stati...

网友评论

      本文标题:vue 智能检索提示--手动定位

      本文链接:https://www.haomeiwen.com/subject/ullqultx.html