我有一个函数 A,它在内部使用函数 B,我想在函数 A 内部使用函数 B 的返回变量,但它总是给我未定义的。
我在网上搜索了很多答案,但我越来越绝望。
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(40.714352, -74.005973);
....
}
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
**latlng=codeAddress("lisboa")**;
}
function codeAddress(a) {
geocoder.geocode( { 'address': a}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
latlong=results[0].geometry.location;
alert(latlong);
return latlong;
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});