【发布时间】:2012-03-01 17:32:52
【问题描述】:
我已经让它工作了一点,但似乎无法弄清楚让 for 循环传递正确值的确切措辞是什么。
for(i=0; i < the_stores.length; i++) {
uid = the_stores[i].id;
// get the lat long and write info to the console
geocoder.getLatLng(the_stores[i].address, function(point) { return callbackFunc(point, uid); });
}
function callbackFunc(point, myID) {
if(point !== null) {
console.log(point.toString());
console.log(myID);
} else {
return false;
}
}
我正在使用 Google Maps API v2。我希望 for 循环在循环的每次迭代中将不同的 uid 值传递给回调函数,但现在它每次都传递相同的值。有人知道如何在这里获得所需的效果吗?我觉得我很接近。谢谢!
【问题讨论】:
标签: javascript google-maps asynchronous callback closures