我寻找错误,但找不到。由于某种原因,任何谷歌地图 infoWindow 总是显示相同的信息。
这是一个咖啡脚本代码
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;
});
那么错误在哪里呢?