【发布时间】:2014-03-16 03:59:20
【问题描述】:
在下面的代码中,当我停止 FireBug 中的代码时,“结果”对象是一个很好的数组,其中填充了 良好的地理编码值。
但是,我放入的 locations[] 数组中充满了所有“undefined”值。
这难道不是不可能的,因为我每次都能看到 results[0] 运行良好吗?
var locations = [];
function makeCallback(addressIndex) {
var geocodeCallBack = function (results, status) {
if (status == "success") {
locations[addressIndex] = results[0];
}
};
return geocodeCallBack;
}
$(function() {
for (var x = 0; x < addresses.length; x++) {
$.getJSON('http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=' + addresses[x], null, makeCallback(x));
}
});
【问题讨论】:
标签: javascript jquery google-maps geocoding google-geocoding-api