vue調用高德地圖


最近的項目有用到vue調用高德地圖,就對高德地圖的調用以及總結,以方便自己以后使用,希望也能幫到你們。

1.在頁面中引入高德地圖JavaScript API入口腳本

<script type="text/javascript" src="http://webapi.amap.com/maps?v=1.4.4&key=您申請的key值"></script>

2.在body中添加一個容器承載地圖,以及設置div的大小和樣式

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

3.初始化地圖

loadmap() {
const that = this;
const map = new AMap.Map('container', {
zoom: 9
});
AMap.plugin('AMap.Geocoder', function () {
var geocoder = new AMap.Geocoder({
city: "010" //城市,默認:“全國”
});
var marker = new AMap.Marker({
map: map,
bubble: true
});
//為地圖注冊click事件獲取鼠標點擊出的經緯度坐標
map.on('click', function (e) {
//設置地圖上所標點的坐標
marker.setPosition(e.lnglat);
//逆地理編碼
geocoder.getAddress(e.lnglat, function (status, result) {
if (status == 'complete' && result.info === 'OK') {
// console.log(result.regeocode.formattedAddress)
that.ruleForm.address = result.regeocode.formattedAddress;
}
})
})

});
},

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM