Vue引入高德地圖并觸發(fā)實(shí)現(xiàn)多個(gè)標(biāo)點(diǎn)的示例詳解
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)信息窗體,打開(kāi)初始化就出現(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)信息窗體,打開(kāi)初始化就出現(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)看官方文檔
綜上就是簡(jiǎn)答使用高德地圖分全部過(guò)程,具體需求請(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)文章
vue面試created中兩次數(shù)據(jù)修改會(huì)觸發(fā)幾次頁(yè)面更新詳解
這篇文章主要為大家介紹了vue面試created中兩次數(shù)據(jù)修改會(huì)觸發(fā)幾次頁(yè)面更新問(wèn)題解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12
想到頭禿也想不到的Vue3復(fù)用組件還可以這么hack的用法
這篇文章主要為大家介紹了想到頭禿也想不到的Vue3復(fù)用組件還可以這么hack的用法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04
vue給對(duì)象動(dòng)態(tài)添加屬性和值的實(shí)例
今天小編就為大家分享一篇vue給對(duì)象動(dòng)態(tài)添加屬性和值的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-09-09
vue?el-switch初始值(默認(rèn)值)不能正確顯示狀態(tài)問(wèn)題及解決
這篇文章主要介紹了vue?el-switch初始值(默認(rèn)值)不能正確顯示狀態(tài)問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10
基于Vue實(shí)現(xiàn)簡(jiǎn)單的權(quán)限控制
這篇文章主要為大家學(xué)習(xí)介紹了如何基于Vue實(shí)現(xiàn)簡(jiǎn)單的權(quán)限控制,文中的示例代碼講解詳細(xì),具有一定的參考價(jià)值,需要的小伙伴可以了解一下2023-07-07
vue循環(huán)中點(diǎn)擊選中再點(diǎn)擊取消(單選)的實(shí)現(xiàn)
這篇文章主要介紹了vue循環(huán)中點(diǎn)擊選中再點(diǎn)擊取消(單選)的實(shí)現(xiàn),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-09-09
vue項(xiàng)目初始化到登錄login頁(yè)面的示例
今天小編就為大家分享一篇vue項(xiàng)目初始化到登錄login頁(yè)面的示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-10-10

