Vue3使用百度地圖簡(jiǎn)單易懂

1、去官網(wǎng)百度地圖開放平臺(tái)申請(qǐng)密鑰:https://lbsyun.baidu.com/index.php?title=jspopular3.0/guide/getkey

image.png

image.png

image.png

2、在public/index.html中引入

<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=你的密鑰ak"></script>

3、渲染地圖

<!-- vue 3 引入百度api -->
<template>
  <div id="allmap"></div>
</template>
 
<script>
import { defineComponent, nextTick, onMounted } from "vue";
export default defineComponent({
  setup() {
    onMounted(() => {
      nextTick(() => {
        initMap();
      });
    });
    const initMap = () => {
      let Bmap = window.BMap;
      let map = new Bmap.Map("allmap");
      map.centerAndZoom(new Bmap.Point(104.04263635868074, 30.556100647961866),11);
    };
    return {} ;
  },
});

</script>
<style  scoped>
  #allmap {
    width: 100%;
    height: 400px;
  }
</style>

提示:如有錯(cuò)誤請(qǐng)與我聯(lián)系謝謝!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容