Questions about reverse Geocoding in Amap web JS API

this is an example of Amap"s reverse geocoding. (JS), wants to try to put it in a separate function and return the address, but if you write it this way, you can see that the breakpoint has successfully called API. Address has an address value, but when return is undefined, with the funtion code I wrote. The little woman waited silently for Daniel"s advice and was grateful.

AMap.plugin("AMap.Geocoder", function() {
  var geocoder = new AMap.Geocoder({
    // city adcode  citycode
    city: "010"
  })
 
  var lnglat = [116.396574, 39.992706]

  geocoder.getAddress(lnglat, function(status, result) {
    if (status === "complete" && result.info === "OK") {
        // result
    }
  })
})

function written by myself

function test(lnglat) {
    var address;
    // 
    var geocoder = new AMap.Geocoder({
        radius: 1000,
        extensions: "all",
        city:""
    });
    // 
      geocoder.getAddress(lnglat,function(status,result){
      if (status === "complete" && result.info === "OK") {
          address = result.regeocode.formattedAddress; //
          return address;
            }else{
                return "";
            }
      });
}
Mar.18,2021

because geocoder.getAddress () is asynchronous.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eafab1-2278.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eafab1-2278.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?