我有这段代码,
geocoder = new GClientGeocoder();
var state;
function addAddressToMap(response) {
if (!response || response.Status.code != 200) {
alert("Sorry, we were unable to geocode that address");
}
else {
place = response.Placemark[0];
state = place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
}
}
// showLocation() is called when you click on the Search button
// in the form. It geocodes the address entered into the form
// and adds a marker to the map at that location.
function showLocation() {
var address = "mutiara damansara";
geocoder.getLocations(address, addAddressToMap);
return state;
}
好的,更新了代码。我尝试实例化showLocation()
,但变量state
未由addAddressToMap
函数更新。
由于
答案 0 :(得分:0)
您的更新代码有助于更好地了解图片。
看起来addAddressToMap()
期待函数参数的响应变量。
当geocoder.getLocations(address,addAddressToMap)
调用时,没有传递回复。
因此,第一个if
语句!response
为真,state
仍未设置。
要修复,您需要在致电addAddressToMap()
时传递内容。看起来某些东西是脚本中其他地方的XMLHttpRequest
(Ajax)对象。