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 "";
}
});
}