【发布时间】:2017-11-21 04:40:45
【问题描述】:
所以谷歌地图信息窗口总是显示最后一个地图项的内容。根据一些研究,我偶然发现了this。但是它仍然对我不起作用,这是我的代码。
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);
});
}
我在 Stackoverflow 上浏览了很多相关项目,但它们似乎没有用。它们似乎都已经可以访问 latlang,因此它们的结构不同。我必须先使用 .getJson 方法来检索地址 latlang,然后再创建标记。
【问题讨论】:
标签: google-maps google-maps-api-3 infowindow