1.demo例子说明
var gDivId; //js全局变量
function geocoder(lastLon,lastLat,result) {
alert("lastLon:"+lastLon);
alert("lastLat:"+lastLat);
alert("result:"+result);
gDivId = result; //赋值给全局变量
}
function testff(){
alert("gDivId: " + gDivId); //读取全局变量
}
2.应用在高德地图中,根据经纬度来查询地址信息
无标题文档 
 
121.432921, 31.196159
var mapObj;
var gDivId;
function geocoder(lastLon,lastLat,result) {
gDivId = result; //赋值给全局变量
//已知点坐标
var lnglatXY = new AMap.LngLat(lastLon,lastLat);
mapObj = new AMap.Map("iCenter", {
view: new AMap.View2D({
center:new AMap.LngLat(lastLon,lastLat),//地图中心点
zoom:13 //地图显示的缩放级别
})
});
var MGeocoder;
//加载地理编码插件
mapObj.plugin(["AMap.Geocoder"], function() {
MGeocoder = new AMap.Geocoder({
radius: 1000,
extensions: "all"
});
//返回地理编码结果
AMap.event.addListener(MGeocoder, "complete", geocoder_CallBack);
//逆地理编码
MGeocoder.getAddress(lnglatXY);
});
//mapObj.setFitView();
}
//回调函数
function geocoder_CallBack(data) {
//返回地址描述
address = data.regeocode.formattedAddress;
//返回结果拼接输出,需要Jquery的支持。
//$("#"+gDivId).html(address);
document.getElementById(gDivId).innerHTML = address;
}