vue使用高德地图显示坐标

index.html引入

<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=847384cfd259b9042e88e96e851ae791"></script>

vue main.js引入

import AMap from 'vue-amap'; // 高德
//地图key
AMap.initAMapApiLoader({
  key: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',//密钥
  plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType',
    'AMap.PolyEditor', 'AMap.CircleEditor', 'AMap.Geolocation'
  ],
  v: '1.4.15'
});
Vue.use(AMap);
<template>
	<div id="mapDiv"></div>
</template>
<script>
export default {
  data () {
    return {
      map: null
    };
  },

  created () { },

  mounted () {
    this.drawMap();
  },
  destroyed () {
    if (this.map != null) {
      this.map.destroy();
    }
  },

  methods: {
    drawMap () {
      AMap.plugin('AMap.PlaceSearch', () => {
        var placeSearch = new AMap.PlaceSearch(); //构造地点查询类
        placeSearch.search('地址', (status, result) => {
          if (result.info === 'OK') {
            var lat = result.poiList.pois[0].location.Q;
            var lng = result.poiList.pois[0].location.R;
            this.map = new AMap.Map('mapDiv', {
              resizeEnable: true,
              center: [lng, lat], //地图中心点
              zoom: 20 //地图显示的缩放级别
            });// 创建一个 Marker 实例:
            var marker = new AMap.Marker({
              position: new AMap.LngLat(lng, lat),   // 经纬度对象
              title: '北京',
              icon: 'https://webapi.amap.com/theme/v1.3/markers/n/end.png'
            });
            // 将创建的点标记添加到已有的地图实例:
            this.map.add(marker);
          }
        }); //关键字查询查询
      });
    }
  }
}
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值