2016-05-04 10 views
0

なぜ私はマーカーの情報ウィンドウの内容に自分のアドレスを取得できないのですか?私のループでは、geocoderstatusの前に私は私のアドレス情報を持っていますが、geocoderstatus.okの後に私は定義されていないか、私の配列の最後のアドレスしか持っていません。Javascript google maps foreach infowindows

 function geocodeAddress(resultsMap) { 
      // var address = document.getElementById('address').value; 

      var address = ["Brussel","Oostende","Brugge","Gent","Luik"]; 



      for(var i = 0; i < address.length;i++) 
      { 
       //new 
       var geocoder = new google.maps.Geocoder(); 

       var geooptions = { 
        address: address[i] 
       } 




       geocoder.geocode(geooptions, function (results, status) { 
        if (status === google.maps.GeocoderStatus.OK) { 
         // resultsMap.setCenter(results[0].geometry.location) 




         addMarker(resultsMap,address[i], results[0].geometry.location); 




        } else { 
         alert('Geocode was not successful for the following reason: ' + status); 
        } 
       }); 
      } 

     } 

     function addMarker(map,item,location) { 

console.log(item); 

      var marker= new google.maps.Marker({ 
       map: map, 
       position: location, //results[0].geometry.location, 
       title: item 
      }); 

      var infowindow = new google.maps.InfoWindow({ 
       content: item 
      }); 



      marker.addListener('click', function() { 
       infowindow.open(map, marker); 
      }); 

     } 

答えて

0

解決策が見つかったのは、jquery.eachだけです。 Wierdはforループとまったく同じです。

(var item in address)は、インデックスだけで値は取得できないため、どちらも機能しません。

この問題は$(アドレス).each(function(index、item)

関連する問題