【发布时间】:2013-01-13 03:27:48
【问题描述】:
我正在使用 google map api V3 并希望通过使用下一个函数来获取某个地址的位置:
function findAddress(address) {
var geocoder = new google.maps.Geocoder();
var addrLocation = "";
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
addrLocation = "Location is: " + results[0].geometry.location;
} else {
addrLocation = "Not found"; }
});
return addrLocation;
}
然后我尝试调用 findAddress 函数:
function SomeFunction(){
alert(findAddress("New York"));
}
按照我的逻辑,该警报应该返回“addrLocation”值,但它会返回空白消息。我做错了什么?
【问题讨论】:
-
非常感谢!我也发现了同样的问题retrieving lat/long of location using google.maps.geocoder。从异步调用返回值是不可能的,但我可以将这些值存储在全局变量中。谢谢大家。
标签: javascript google-maps-api-3 return-value