我的函数是这样的
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));
当我调用此函数时,我得到空结果,但函数中的警报返回纬度。有什么问题吗?
我认为ops在这个问题中的答案可能会有所帮助:
Google maps geocode API V3在javascript函数中没有返回结果
您可以在解决方案中看到,op使用来自geocoder.geocode的回调。