亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Vue引入高德地圖并觸發(fā)實(shí)現(xiàn)多個(gè)標(biāo)點(diǎn)的示例詳解

 更新時(shí)間:2022年05月28日 10:02:27   作者:張清悠  
這篇文章主要介紹了Vue引入高德地圖并觸發(fā)實(shí)現(xiàn)多個(gè)標(biāo)點(diǎn),主要是在public下的index.html中引入地圖,引入組件設(shè)置寬高100%,本文通過示例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下

1、 在public下的index.html中引入地圖

<link rel="stylesheet"  rel="external nofollow"   />
<script src="https://webapi.amap.com/maps?v=1.4.15&key=申請(qǐng)的key"></script>

2、引入組件設(shè)置寬高100%

<template>
  <div>
    <div id="container" style="width: 100%;height: 550px"></div>
  </div>
</template>

3、數(shù)組形式數(shù)據(jù)固定(一)

<script>
export default {
  data() {
    return {
    //要標(biāo)記的所有點(diǎn)的經(jīng)緯度
      lnglats: [
        [108.909074, 34.254225],
        [108.910766, 34.254348],
        [108.910495, 34.253531],
        [108.909502, 34.253571],
      ],
    }
  },
  mounted() {
    this.carGPSIP()
  },
  methods: {
    carGPSIP() {
      var map = new AMap.Map("container", {resizeEnable: true});//初始化地圖
      //信息窗口實(shí)例
      var infoWindow = new AMap.InfoWindow({offset: new AMap.Pixel(0, -30)});
      //遍歷生成多個(gè)標(biāo)記點(diǎn)
      for (var i = 0, marker; i < this.lnglats.length; i++) {
        var marker = new AMap.Marker({
          position: this.lnglats[i],//不同標(biāo)記點(diǎn)的經(jīng)緯度
          map: map
        });
        marker.content = '我是第' + (i + 1) + '個(gè)Marker';
        marker.on('click', markerClick);
        marker.emit('click', {target: marker});//默認(rèn)初始化不出現(xiàn)信息窗體,打開初始化就出現(xiàn)信息窗體
      }
      function markerClick(e) {
        infoWindow.setContent(e.target.content);
        infoWindow.open(map, e.target.getPosition());
      }
      map.setFitView();
      }
    },
}
</script>

4、用ajax請(qǐng)求后端真是接口(二)

<template>
      <div id="container" style="width: 100%;height: 550px"></div>  
      <!-- 設(shè)置寬和高 -->
</template>

<script>
export default {
  data() {
    return {
    //要標(biāo)記的所有點(diǎn)的經(jīng)緯度
      Coordinate:[]
      //  Coordinate:[
      //    {
      //      lng:"54.323243",
      //      lat:"43.654322"
      //    }
      //  ]  //后端返回的數(shù)據(jù)格式

    }
  },
  mounted() {
    this.carGPSIP()
  },
  methods: {
    carGPSIP() {
      var map = new AMap.Map("container", {resizeEnable: true});//初始化地圖
      //信息窗口實(shí)例
      var infoWindow = new AMap.InfoWindow({offset: new AMap.Pixel(0, -30)});
      //遍歷生成多個(gè)標(biāo)記點(diǎn) 因后端返回是map格式因此需要判斷code
    $ajax.positionType({}, ({ code, data }) => {
        if (code == 200) {
          console.log(data);
          this. Coordinate = data.deviceList; //拿到數(shù)據(jù)
          let  Coordinate = data.deviceList;  //定義Coordinate
          for (var i = 0; i < this. Coordinate.length; i++) {
            var marker = new AMap.Marker({
              position: new AMap.LngLat( Coordinate[i].lng,  Coordinate[i].lat), //不同標(biāo)記點(diǎn)的經(jīng)緯度
              map: map,
            });
             marker.content = '我是第' + (i + 1) + '個(gè)Marker';
            marker.on("click", markerClick);
            marker.emit("click", { target: marker }); //默認(rèn)初始化不出現(xiàn)信息窗體,打開初始化就出現(xiàn)信息窗體
          }
          function markerClick(e) {
            infoWindow.setContent(e.target.content);
            infoWindow.open(map, e.target.getPosition());
          }
          map.setFitView();
        }
      });
      function markerClick(e) {
        infoWindow.setContent(e.target.content);
        infoWindow.open(map, e.target.getPosition());
      }
      map.setFitView();
      }
    },
}
</script>
<style>
</style>

5、其他需求請(qǐng)看文檔請(qǐng)看官方文檔

lbs.amap.com/api/javascr…

綜上就是簡答使用高德地圖分全部過程,具體需求請(qǐng)參照高德官方api

到此這篇關(guān)于Vue引入高德地圖并觸發(fā)實(shí)現(xiàn)多個(gè)標(biāo)點(diǎn)的文章就介紹到這了,更多相關(guān)vue高德地圖觸發(fā)多個(gè)標(biāo)點(diǎn)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論