我尝试了不同的变量范围,但似乎都没有工作?我的回调得到了一个有效的结果,但是无论我分配给它的变量的范围如何,一旦回调结束,我就会丢失值??
var geocoder;
var Lat;
var Long;
function codeAddress()
{
var geocoder = new google.maps.Geocoder();
var addy1......
geocoder.geocode({ 'address': fullAddress }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK)
{
Lat = results[0].geometry.location.lat();
Long = results[0].geometry.location.lng();
}
else
{
alert("Geocode was not successful for the following reason: " + status);
}
});
alert(Lat);
document.getElementById("Address_AddyLat").type.value = Lat;
document.getElementById("Address_AddyLong").value = Long;
}
感谢您的意见。