vue Baidu Map 官网:https://dafrok.github.io/vue-baidu-map/#/zh/start/installation

javascript 官网:http://lbsyun.baidu.com/jsdemo.htm#d0_1

实现功能:

  1. 搜索地点
  2. 点击地图获取到经纬度和地点信息

vue Baidu Map 安装:

$ npm install vue-baidu-map --save

全局注册

全局注册将一次性引入百度地图组件库的所有组件。

import Vue from 'vue'
import BaiduMap from 'vue-baidu-map' Vue.use(BaiduMap, {
// ak 是在百度地图开发者平台申请的密钥 详见 http://lbsyun.baidu.com/apiconsole/key */
ak: 'YOUR_APP_KEY'
})


使用:

<template>
<baidu-map class="bm-view">
</baidu-map>
</template> <style>
//宽高一定要定义,否则看不见
.bm-view {
width: 100%;
height: 300px;
}
</style>

开始功能:使用搜索插件

    <el-form-item label="输入地址关键词">
<el-input v-model="keyword"/> <!--输入关键词触发搜索-->
<input v-model="location" type="hidden"> <!--定位这个location点 如:厦门 地图打开就地位在厦门-->
</el-form-item>
        <baidu-map
:center="center"
:zoom="15" <!--搜索结果的视图比例-->
:scroll-wheel-zoom="true" <!--是否可以用鼠标滚轮控制缩放-->
@click="getPoint"> <!--地图的点击事件 点击地图获取所需要的信息 如:经度、纬度-->
<!--地图类型,两种:一种是路线一种是绿的那种-->
<bm-map-type :map-types="['BMAP_NORMAL_MAP', 'BMAP_HYBRID_MAP']" anchor="BMAP_ANCHOR_TOP_LEFT"/>
<bm-view class="map"/>
<bm-local-search :keyword="keyword" :auto-viewport="true" style="width:0px;height:0px;overflow: hidden;"/> <!--隐藏下面的地址信息 美观点-->
script: data数据
     location: '厦门',
keyword: '厦门',
zoom: 15,
center: {
lng: 118.206484,
lat: 24.492774
}

事件:获取经纬度 和 地点

getPoint(e) {
// console.log(e)
this.form.lng = e.point.lng
this.form.lat = e.point.lat
/* global BMap */ ****画重点:这里不是注释,是解决eslint报错
const geocoder = new BMap.Geocoder() // 创建地址解析器的实例
geocoder.getLocation(e.point, rs => {
// console.log(rs.addressComponents) // 结构化的地址描述(object)
const province = rs.addressComponents.province // 省
const city = rs.addressComponents.city // 城市
const district = rs.addressComponents.district // 区县
const street = rs.addressComponents.street // 街道
const streetNumber = rs.addressComponents.streetNumber// 门牌号
this.form.address = province + city + district + street + streetNumber // 组装成地址
// console.log(rs.surroundingPois) // 附近的POI点(array) POI:兴趣点 可以是一栋房子、一个商铺、一个邮筒、一个公交站
// console.log(rs.business) // 商圈字段,代表此点所属的商圈(string)
})
},

注意:

eslint 会报错:ESLint: 'BMap' is not defined. (no-undef)

解决办法:参考自文章:https://blog.csdn.net/xiu52t/article/details/84643716

方法1:如上图,在BMap上面加一行注释   /* global BMap */

方法2:在 .eslintrc.js中加代码

globals: { BMap: true },

  

vue Baidu Map --- vue百度地图插件的更多相关文章

  1. 使用Vue Baidu Map对百度地图实现输入框搜索定位

    前端时间需要在页面的输入框输入地址,搜索并在百度地图上获取选定结果的坐标,前端使用了Vue + Element-ui,地图方面直接使用了封装好的百度地图vue组件-vue-baidu-map     ...

  2. Vue Baidu Map 插件的使用

    最近在做一个项目,技术采用的是Vue.js套餐,有个百度地图的需求,当时,大脑宕机,立马去引入百度地图API,当时想到两种方法,一种是在index.html中全局引入js,此法吾不喜,就采用了第二种异 ...

  3. vue百度地图插件

    安装 npm i --save vue-baidu-map 代码 <template> <div> <baidu-map v-bind:style="mapSt ...

  4. vue项目中使用百度地图的方法

    1.在百度地图申请密钥: http://lbsyun.baidu.com/  将 <script type="text/javascript" src="http: ...

  5. 最全vue的vue-amap使用高德地图插件画多边形范围

    一.在vue-cli的框架下的main.js(或者main.ts)中引入高德插件,代码如下: import Vue from 'vue' import VueAMap from 'vue-amap' ...

  6. vue 项目中引用百度地图

    新建map.js export const BaiduMap = { init: function() { const BMapURL = 'https://api.map.baidu.com/api ...

  7. 在Vue框架中使用百度地图

    1.首先在index.html中引入百度地图 <script type="text/javascript" src="http://api.map.baidu.co ...

  8. vue2.0之Vue Baidu Map 局部注册使用

    文档地址:https://dafrok.github.io/vue-baidu-map/#/zh/start/usage 局部注册 <template> <baidu-map id= ...

  9. Vue中加载百度地图

    借助百度地图的 LocalSearch 和 Autocomplete 两个方法 实现方式:通过promise以及百度地图的callback回调函数 map.js 1 export function M ...

随机推荐

  1. linux服务器安装pyspide关于rgnutls.h: No such file or directory 的解决方案

    In file included from src/docstrings.c:4:0: src/pycurl.h:148:30: fatal error: gnutls/gnutls.h: No su ...

  2. Xilinx 7 Serial PUDC_B

    PUDC_B管脚用途 Pull-Up During Configuration (bar) Active-Low PUDC_B input enables internal pull-up resis ...

  3. python全栈开发day112-CBV、flask_session、WTForms

    1.Flask 中的 CBV class Index(views.MethodView): # methods = ["POST"] # decorators = [war,nei ...

  4. Eclipse中如何将项目转成Dynamic Web项目

    项目接手前的同事是使用MyEclipse写的,拿SVN将项目导入eclipse时,web项目就会变成java项目,这时就需要修改配置文件将项目转成web,步骤如下: 1.修改项目配置文件. 要修改的项 ...

  5. Vim使用心得

    马上就要联赛啦. 学习一下vim 这是一个vim文档 http://vimcdoc.sourceforge.net/doc/ 这是一个优秀的vimrc配置 http://www.cnblogs.com ...

  6. eclipse 中 导入git项目无法导入的问题

    研发在git上打了一个分支,需要重新导入分支项目.此时发现与之前相同模式导入失败,不起作用. 解决: 需要在Git Repositories中对应项目下找到.project 文件并进行修改,修改项目名 ...

  7. LCA的在线与离线算法

    在线:链接 离线:链接

  8. swift中Cell的内容定制

    1.cellForTitle 2.register

  9. VUE重修01

    ---恢复内容开始--- 1.框架与库的区别 前端框架与库的区别? jquery 库 -> DOM(操作DOM) + 请求 art-template 库 -> 模板引擎 框架 = 全方位功 ...

  10. 2018-2019-1 20189210 《LInux内核原理与分析》第八周作业

    一 .可执行程序工作原理 程序编译 预处理:gcc -E hello.c -o hello.i 编译:gcc -S hello.i -o hello.s -m32 汇编:gcc -c hello.s ...