当前位置:   article > 正文

VUE 中引入百度地图 定位_"

"

1.安装:

npm install vue-baidu-map --save

2.全局注册,在main.js中引入以下代码:

import BaiduMap from 'vue-baidu-map'

Vue.use(BaiduMap, {

  ak: '你申请的key'

})

3.完整代码:

  1. <template>
  2. <baidu-map :center="center" :zoom="zoom" @ready="handler" style="height:1080px" @click="getClickInfo" :scroll-wheel-zoom='true'>
  3. </baidu-map>
  4. </template>
  5. <script>
  6. export default {
  7. name: 'TestBaiDu',
  8. data () {
  9. return {
  10. center: {lng: 109.45744048529967, lat: 36.49771311230842},
  11. zoom: 13
  12. }
  13. },
  14. methods: {
  15. handler ({BMap, map}) {
  16. var point = new BMap.Point(109.49926175379778, 36.60449676862417)
  17. map.centerAndZoom(point, 13)
  18. var marker = new BMap.Marker(point) // 创建标注
  19. map.addOverlay(marker) // 将标注添加到地图中
  20. var circle = new BMap.Circle(point, 6, { strokeColor: 'Red', strokeWeight: 6, strokeOpacity: 1, Color: 'Red', fillColor: '#f03' })
  21. map.addOverlay(circle)
  22. },
  23. getClickInfo (e) {
  24. console.log(e.point.lng)
  25. console.log(e.point.lat)
  26. this.center.lng = e.point.lng
  27. this.center.lat = e.point.lat
  28. }
  29. }<br>}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/109832
推荐阅读
相关标签