1.进入 lbs.qq.com 成为开者 获取密匙
2. 在 index.html 加上网络的 js
<script src="https://map.qq.com/api/gljs?v=1.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77"></script>
3.在页面使用
<template>
<div class="txMap">
<div id="allmap"></div>
</div>
</template>
<script>
export default{
data () {
return {
dataorigin: '',
pointList: []
};
},
mounted () {
this.initMap2()
},
methods: {
initMap2 () {
console.log("window", window);
// 定义地图中心点坐标
let center = new TMap.LatLng(29.534706, 106.559972);// 坐标靠近中间
// 定义map变量,调用 TMap.Map() 构造函数创建地图
var map = new TMap.Map(document.getElementById("allmap"), {
center: center,
zoom: 15
});
// //初始marker
var marker = new TMap.MultiMarker({
map: map,
styles: {
// mark样式
"marker": new TMap.MarkerStyle({
"width": 25,
"height": 38,
"anchor": { x: 12, y: 32 },
})
},
geometries: [
{
"id": 'demo1',
"styleId": 'marker',
"position": new TMap.LatLng(29.534706,106.559972),
"properties": {
"title": "标记点1",
}
},
{
"id": 'demo2',
"styleId": 'marker',
"position": new TMap.LatLng(29.533587,106.55826),
"properties": {
"title": "标记点2",
}
}
]
});
},
}
}
</script>
<style scoped>
#container{
width: 80%;
margin: 20px auto;
height: 800px;
}
</style>
4. 出现效果