如下图:
代码如下:
const AMap = window.AMap;//一定要引入AMap
data() {
return {
map: null,
jd: "",
wd: "",
weizhi: "",
};
},
// 地图初始化
initMap() {
this.map = new AMap.Map("map001", {
center: [118.798039, 31.96875], //中心点坐标
zoom: 15, //级别
});
let self = this;
//为地图注册click事件获取鼠标点击出的经纬度坐标
this.map.on("click", (e) => {
self.jd = e.lnglat.getLng();//经度
self.wd = e.lnglat.getLat();//纬度
self.weizhi = new AMap.Marker({
icon: "https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",//点的图标
position: [self.jd, self.wd],//点的坐标
});
this.map.add(self.weizhi);
});
}