高德地图vue的调用

import  AMap  from  'vue-amap'
AMap. initAMapApiLoader({
   key:  '5f7b2f69a795d2e96d762419e81c5c1f',//自己申请
   plugin: [ 'AMap.Autocomplete''AMap.PlaceSearch''AMap.Scale''AMap.OverView''AMap.ToolBar',
    'AMap.MapType''AMap.PolyEditor''AMap.CircleEditor', 'AMap.Geolocation','AMap.Geocoder']
})
Vue. use( AMap)
< template >
   < div >
     < div  class= "amap-page-container" >
       < el-amap  vid= "amapDemo" : zoom= "zoom" : center= "center"  class= "amap-demo" : plugin= "plugin" : events= "events" >
         < el-amap-info-window : position= "mywindow.position" : content= "address" : visible= "mywindow.visible" : events= "mywindow.events" ></ el-amap-info-window >
         < el-amap-marker : position= "marker.position" : events= "marker.events" : visible= "marker.visible" : draggable= "marker.draggable" ></ el-amap-marker >
         < el-amap-circle : center= "circle.center" : radius= "circle.radius" : fillOpacity= "circle.fillOpacity" : events= "circle.events"
          : strokeColor= "circle.strokeColor" : strokeStyle= "circle.strokeStyle" : fillColor= "circle.fillColor" ></ el-amap-circle >
       </ el-amap >
       < div  class= "toolbar" >
         < span  v-if= "loaded" >
          location: lng = {{ lng }} lat = {{ lat }}
         </ span >
         < span  v-else >正在定位 </ span >
       </ div >
       < span >{{ address }} </ span >
     </ div >
   </ div >
</ template >

< style >
   .amap-page-container {
     height500px;
  }
</ style >


< script >
   export  default {
     data() {
       let  self =  this;
       return {
         events: {
           click( e) {
             let { lnglat} =  e. lnglat;
             self. lng =  lng;
             self. lat =  lat;
             var  geocoder =  new  AMap. Geocoder({
               radius:  1000,
               extensions:  "all"
            });
             geocoder. getAddress([ lnglat],  function ( statusresult) {
               if ( status ===  'complete' &&  result. info ===  'OK') {
                 if ( result &&  result. regeocode) {
                   self. address =  result. regeocode. formattedAddress;
                   self. $nextTick();
                }
              }
            });
          }
        },
         searchOption: {
           city:  '上海',
           citylimit:  true
        },
         zoom:  15,
         center: [ 121.527328531.21515000],

         circle: {
           clickable:  true,
           center: [ 113.3611422.31889],
           radius:  200,
           fillOpacity:  0.3,
           strokeStyle:  'dashed',
           fillColor:  '#FFFF00',
           strokeColor:  '#00BFFF',

           loaded:  false,

        },
         lng:  0,
         lat:  0,
         address:  '',

         marker: {
           position: [ 113.3611422.31889],
           events: {
             click: ()  => {
               if ( this. mywindow. visible ===  true) {
                 this. mywindow. visible =  false
              }  else {
                 this. mywindow. visible =  true
              }
            },
             dragend: ( e=> {
               this. markers[ 0]. position = [ e. lnglat. lnge. lnglat. lat]
            }
          },
           visible:  true,
           draggable:  false
        },
         mywindow: {
           position: [ 113.3611422.31889],
           content:  '<h4>该点数据信息</h4><div class="text item">Information A: ...</div><div class="text item">Information B: ...</div>',
           visible:  true,
           events: {
             close() {
               this. mywindow. visible =  false
            }
          }
        },

         plugin: [{
           pName:  'Geolocation',
           events: {
             init( o) {
               // o 是高德地图定位插件实例
               o. getCurrentPosition(( statusresult=> {
                 if ( result &&  result. position) {
                   self. lng =  result. position. lng;
                   self. lat =  result. position. lat;
                   self. center = [ self. lngself. lat];
                   self. address =  result. position. formattedAddress;
                   self. loaded =  true;
                   self. $nextTick();
                   self. address =  result. formattedAddress;
                   console. log( result);
                }
              });
            }
          }
        }]

      };
    }
  }

</ script >

//很多功能还未完善

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值