1.npm下载
npm i @amap/amap-jsapi-loader --save
npm install coordtransform --涉及到坐标转换不想自己写的可以安装这个
2.index.html文件中引入
<script type="text/javascript">
window._AMapSecurityConfig = {
securityJsCode: "安全秘钥",
};
</script>
3.具体页面中定义容器
<div class="bottom" id="detailsMap"></div>
4.
import AMapLoader from "@amap/amap-jsapi-loader";
AMapLoader.load({
key: "应用key",
version: "2.0",
plugins: ["AMap.Scale", "AMap.GeoJSON", "AMap.Geocoder"],
})
.then((AMap) => {
this.map = new AMap.Map("detailsMap", {
zoom: 13,
zooms: [8, 20],
center: [104.167501, 31.12678],
features: ["road", "point"],
});
this.geocoder = new AMap.Geocoder({
radius: 1000
});
this.map.on('click', this.clickMap);
})
.catch((err) => {
console.log(err, "err");
});