vue2高德地图基本使用(记录)

<template>
  <div>
    <div id="container"></div>
  </div>
</template>

<script>
//  使用前先下载 npm i @amap/amap-jsapi-loader --save
import AMapLoader from '@amap/amap-jsapi-loader';

export default {
  data() {
    return {
      map: null //初始化 map 对象
    }
  },
  methods: {
    initMap() {
      AMapLoader.load({
        key: "此处填入我们注册账号后获取的Key", 
        version: "2.0", //指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
        plugins: [''], //需要使用的的插件列表,如比例尺'AMap.Scale'等
      }).then((AMap) => {
        this.map = new AMap.Map("container", { //设置地图容器id
          pitch:0, // 地图俯仰角度,有效范围 0 度- 83 度
          viewMode: "3D", //是否为3D地图模式
          zoom: 15, //初始化地图级别
          terrain: true, // 开启地形图
          mapStyle: "amap://styles/dark",//更换地图样式
          center: [116.397499,39.908722], //初始化地图中心点位置
        });
        this.markers(AMap)
      }).catch(e => {
        console.log(e);
      })
    },
    markers(AMap){
      // 创建一个 Marker 实例:
      let arr = [{lon:116.397499,lat:39.908722},{lon:116.397399,lat:39.9037344},{lon:116.392399,lat:39.905733}]
      arr.forEach((value,index,array) => {
        let postion = [];
        postion.push(array[index].lon/1)
        postion.push(array[index].lat/1)
        let marker = new AMap.Marker({
          map: this.map,
          icon: 'https://webapi.amap.com/theme/v1.3/markers/n/mark_bs.png',
          position: postion,
          offset: new AMap.Pixel(-13, -30)
        });
        this.map.add(marker);
        console.log(postion,"postion")
      })
      // var marker = new AMap.Marker({
      //   position: new AMap.LngLat(116.397499,39.908722),   // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
      //   title: '北京'
      // });

// 将创建的点标记添加到已有的地图实例:

// 移除已创建的 marker
//      this.map.remove(marker);
    }
  },
  mounted() {
    //DOM初始化完成进行地图初始化
    this.initMap();
  }
}
</script>

<style>
#container {
  width: 80%;
  height: 800px;
  margin: 50px auto;
  border: 1px solid red;
}
</style>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值