【发布时间】:2019-12-02 19:25:52
【问题描述】:
我创建了一些代码来创建谷歌地图,它会提取一些标记数据。我将如何构造此代码以一次只打开一个信息窗口?回答越直接越好。
function initializeLocations(locations) {
$.each(locations, function (i, location) {
var marker = new google.maps.Marker({
position: location.geo,
map: map,
title: location.name
});
var contentName = '<br><b>' + location.name + '</b><br>';
var contentLink = '<a href="' + location.url + '">More Info</a>';
var contentAddress = location.address;
var content = contentName + contentAddress + contentLink
var infoWindow = new google.maps.InfoWindow({
content: content
});
marker.addListener('click', function() {
infoWindow.open(map, this);
});
});
}
【问题讨论】:
标签: javascript maps infowindow