Amap obtains address information based on longitude and latitude

Mainly using the method of geocoding and reverse geocoding in AMAP . According to reverse geocoding: geographical coordinates (latitude and longitude) are converted into address description information, which corresponds to the getAddress method of AMap.Geocoder. The specific code used isgetAddress

   let position = [lng,lat] //位置的经纬度 
   new AMap.plugin("AMap.Geocoder", () => {
    
    
        const geocoder = new AMap.Geocoder({
    
    
          // city 指定进行编码查询的城市,支持传入城市名、adcode 和 citycode
          city: "028" //成都
        });
        geocoder.getAddress(position, (status, result) => {
    
    
          if (status === "complete" && result.info === "OK") {
    
    
            // result为对应的地理位置详细信息
            this.place = result.regeocode.formattedAddress;  
            // this.place为返回的具体地理位置信息,里面无法使用return回来!
          }
        });
      });

Finally look at the effect

This is the transmitted longitude and latitude and the analyzed geographical location.
Insert image description here

If you need forward analysis to convert the geographical location into longitude and latitude, you need to use getLocationthis method.
The steps are the same. For details, please see the official website.

Geocoding and reverse geocoding

Guess you like

Origin blog.csdn.net/Jet_Lover/article/details/128190289