高德获取地址/经纬度
1.获取详细地址:
AMap.plugin("AMap.Geocoder", () => {
geocoder = new AMap.Geocoder();
if (geocoder) {
geocoder.getAddress([lng, lat], (status, result) => {
if (status === "complete" && result.regeocode) {
var address = result.regeocode.formattedAddress;
fun(address);
}
});
}
});
2.获取经纬度:
AMap.plugin("AMap.Geocoder", () => {
geocoder = new AMap.Geocoder();
if (geocoder) {
geocoder.getLocation('山西省太原市小店区', (status, result) => {
if (status === "complete" && result.geocodes.length) {
const lngLat = result.geocodes[0].location;
fun(lngLat); // 方法参数调用或者直接返回都可以
}
});
}
});
3.获取可视区域最大经纬度:
getBounds() { const map = new AMap.Map(this.$refs.gaodeMap, this.mapConfig); const bounds: any = map.getBounds(); const nE: any = [ bounds.getNorthEast().getLng(), bounds.getNorthEast().getLat() ]; const sW: any = [ bounds.getSouthWest().getLng(), bounds.getSouthWest().getLat() ]; let maxLon = nE[0] > sW[0] ? nE[0] : sW[0]; let minLon = nE[0] > sW[0] ? sW[0] : nE[0]; let maxLat = nE[1] > sW[1] ? nE[1] : sW[1]; let minLat = nE[1] > sW[1] ? sW[1] : nE[1]; return { maxLon, minLon, maxLat, minLat }; }
记录进步!!!

浙公网安备 33010602011771号