我查找錯誤,但無法找到它。任何谷歌地圖infoWindow總是出於某種原因顯示相同的信息。Google maps api中的infoWindow數組
這裏是一個CoffeeScript的代碼
infowindow = new google.maps.InfoWindow()
for company in companiesData
marker = new google.maps.Marker({
position: new google.maps.LatLng(company.latitude, company.longitude)
map: map
})
#debugger ---> each company.name is different!
google.maps.event.addListener(marker, 'click',()->
infowindow.setContent(company.name)
infowindow.open(map,this)
)
我調試它,看到每個company.name是不同的。
輸出的JavaScript
infowindow = new google.maps.InfoWindow();
_results = [];
for (_j = 0, _len1 = companiesData.length; _j < _len1; _j++) {
company = companiesData[_j];
marker = new google.maps.Marker({
position: new google.maps.LatLng(company.latitude, company.longitude),
map: map
});
_results.push(google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(company.name);
return infowindow.open(map, this);
}));
}
return _results;
});
那麼,是一個錯誤?
沒錯。但爲什麼它工作?有什麼不同? – Alexandre
查看我在回覆的底部發布的鏈接,其中顯示「此處解釋」。 – Marcelo