因此谷歌地图infowindow总是显示最后的地图项目的内容。基于一些研究,我偶然发现了this。但它仍然不适合我这里是我的代码。谷歌地图infowindow显示相同的内容
function bindInfoWindow(marker, map, infowindow, html) {
marker.addListener('click', function() {
infowindow.setContent(html);
infowindow.open(map, this);
});
}
for (var x = 0; x < filtered_pins.length; x++) {
var links = filtered_pins[x].description + '<a href="' + filtered_pins[x].slug + '">read more..</a>';
links_arr.push(links);
$.getJSON('http://maps.googleapis.com/maps/api/geocode/json?address=' + filtered_pins[x].city + '&sensor=false', null, function (data) {
//console.log('4th'+ links);
var p = data.results[0].geometry.location
var latlng = new google.maps.LatLng(p.lat, p.lng);
var marker = new google.maps.Marker({
position: latlng,
map: map,
});
var infowindow = new google.maps.InfoWindow();
//marker.addListener('click', function() {
//infoWindow.setContent(links);
// infowindow.open(map, this);
//});
bindInfoWindow(marker, map, infowindow, links);
my_markers.push(marker);
});
}
我走过不少#2相关项目的走了,但他们似乎并没有被service.They一切似乎已经进入latlang所以他们的结构是不同的。我必须使用.getJson方法首先检索地址latlang然后创建标记。
非常感谢你的工作。不知道为什么这个工作,并将函数的内容移动到我的forloop不。 – sqwale