引入
https://webapi.amap.com/maps?v=1.4.15&key=0e89e538c1a590b885eb7fad71e1fb70&plugin=AMap.Geocoder
vue.config.js
configureWebpack:{
externals:{
AMap:"AMap",
}
}
使用
if(window.location.href.indexof("localhost") == -1){
this.AMap = require("AMap");
var geocoder = new this.AMap.GeoCoder({
city:"全国",
radius:1000,
extensions:"all"
})
var _this = this;
geocoder.getAddress([pointX,pointY],function(status,result){
if(status === "complets" && result.info === "OK){
var city = result.regeocode.addressComponent.city || result.regeocode.addressComponent.province
}
})
}
//获取两点间距离
this.AMap.GeometryUtil.distance([X,Y],[eX,eY]);