我试图通过点击文字打开infowindow但是当我有群集时我不能打电话给任何帮助??
图片:http://s4.postimg.org/khw51khot/aaa.png
function open_window(io) { // my function to open info window from external link
//alert(io);
infowindow.setContent(locations[io][0]);
infowindow.open(map, marker);
(marker, io);
}
function initialize() {
var infowindow = new google.maps.InfoWindow();
var center = new google.maps.LatLng(37.4419, 110.1419);
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 3,
center: center,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var markers = [];
for (var i = 0; i < locations.length; i++) {
var latLng = new google.maps.LatLng(locations[i][2], locations[i][1]);
var marker = new google.maps.Marker({
position: latLng
});
markers.push(marker);
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
var markerCluster = new MarkerClusterer(map, markers);
}
google.maps.event.addDomListener(window, 'load', initialize); < /script>
</head >
< body >
< h3 > < /h3>
<table border="1">
<tr><td>
<div id="map-container"><div id="map"></div > < /div>
</td >
< td width = "400px" >
< div style = "height:600px;width:400px;border:1px solid #ccc;font:12px/26px Georgia, Garamond, Serif;overflow:auto;" >
< script type = "text/javascript" > // script to generate the links to open window can pass number already tried alert function
for (io = 0; io < locations.length; io++) {
document.write(" <p id=" + io + " onclick='open_window(this.id)'>");
document.write(locations[io][3]);
document.write(io);
document.write("</p>");
} < /script>
</div >
< /td>
</tr >
< /table>
如果没有群集,我可以打开信息窗口,我尝试做的是打开infowindow并将焦点映射到该制造商。
答案 0 :(得分:0)
问题解决了 1-)将var markers []置于初始化之外 2-)创建事件触发器功能并触发标记点击事件 3-)将位置设置为标记位置map.setCenter(marker.getPosition()); 4-)将簇限制为9变焦maxZoom:9
infowindow从外部链接调用并放置在它应该是的位置:) 我用3个咖啡+ 1个可乐+ 1个士力架巧克力棒做成。