【发布时间】:2014-05-20 10:20:55
【问题描述】:
我的功能是这样的。
function getLatLong(address){
var latitude="";
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
latitude = results[0].geometry.location.lat();
alert(latitude);
});
return latitude;
}
alert(getLatLong(co));
当我调用此函数时,我得到空结果,但函数中的警报返回纬度。有什么问题?
【问题讨论】:
-
地理编码请求是异步的,因此您的返回语句可以在地理编码功能完成之前执行。见developers.google.com/maps/documentation/javascript/geocoding
标签: google-maps