如何将全局变量值导入geocoder_map.geocode(..)函数?

时间:2013-04-04 11:59:39

标签: javascript google-maps

var addressArr = new Array();
....
for(var i=0;i<addressArr.length;i++){
      geocoder_map.geocode( { 'address': addressArr[i]}, function(results, status) {

        alert(addressArr[i]); // here i found undefined - how i will find this value here ?

      });
}

我已经尝试过隐藏字段中的值,如..

 var addressArr = new Array();
    ....
 document.getElementById("hidAddressStr").value = addressArr[i];
    for(var i=0;i<addressArr.length;i++){
          geocoder_map.geocode( { 'address': addressArr[i]}, function(results, status) {

            alert(document.getElementById("hidAddressStr").value); // i found only single value from here

          });
}

1 个答案:

答案 0 :(得分:0)

尝试使用单独的功能

var testFunction = function(str) {
    geocoder_map.geocode( { 'address': str}, function(results, status) {
        alert(str);
    });
}

for(var i=0;i<addressArr.length;i++){
    testFunction(addressArr[i]);
}