• vue结合百度地图(vue-baidu-map)根据经纬度查询省市街道信息


    该demo使用Ant Design Pro Vue

    百度地图使用 vue-baidu-map 

     1 <baidu-map
     2   class="map"
     3   @ready="handler"
     4   style="height: 500px;"
     5   :center="center"
     6   :zoom="15"
     7   :map-click="false">
     8   <div>
     9     <bm-marker
    10       :dragging="true"
    11       animation="BMAP_ANIMATION_BOUNCE"
    12       :position="center"
    13       @dragend="dragend"
    14     >
    15     </bm-marker>
    16   </div>
    17 </baidu-map>
     1 methods: {
     2     handler: function ({ BMap, map }) {
     3       map.enableScrollWheelZoom(true)
     4       // map.centerAndZoom('青岛市', 13)
     5       const hide = this.$message.loading('正在获取当前省市请稍候..', 0)
     6       const _this = this
     7       const geolocation = new BMap.Geolocation()
     8       geolocation.getCurrentPosition(function (r) {
     9         setTimeout(hide, 1000)
    10         console.log(r)
    11         _this.center = { lng: r.longitude, lat: r.latitude }        // 设置center属性值
    12         // _this.autoLocationPoint = { lng: r.longitude, lat: r.latitude }        // 自定义覆盖物
    13         _this.initLocation = true
    14       }, { enableHighAccuracy: true })
    15 
    16       window.map = map
    17       // 赋值,方便调用,本节被用到
    18       this.BMap = BMap
    19       this.map = map
    20     },
    21     // 拖动结束后
    22     dragend (e) {
    23       this.position = e.point
    24       const _this = this
    25       console.log(e.point)
    26       console.log(this.position)
    27       const gc = new this.BMap.Geocoder()
    28       gc.getLocation(e.point, function (rs) {
    29         console.log(rs)
    30         // var addComp = rs.addressComponents
    31         // this.addr = addComp.province + ', ' + addComp.city + ', ' + addComp.district + ', ' + addComp.street + ', ' + addComp.streetNumber
    32         _this.addr = rs.address
    33       })
    34     }
  • 相关阅读:
    【题解】[USACO07OPEN]Dining G
    【学习笔记】拉格朗日插值
    【题解】简单的数学题
    docker-compose编排参数详解
    Harbor搭建企业级docker仓库
    centos7制作U盘启动盘
    c语言输入矩阵的对角线之和
    搭建rsync+inotify实现实时备份
    CentOS7添加自定义脚本服务
    Linux搭建NFS服务
  • 原文地址:https://www.cnblogs.com/caoxen/p/11434647.html
Copyright © 2020-2023  润新知