这个问题与 google maps API v3 中的信息窗口有关..
目前我循环这个函数并放置标记..
function addPostCode(zip, html)
{
geocoder.geocode( { 'address': zip}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
name: zip
});
});
现在我想添加一个具有独特 HTML 的信息窗口,但是我想要以下行为......
当一个信息窗口被事件打开时,任何当前的信息窗口都将关闭,只留下新的信息窗口。
这可能吗?我该怎么做?事实证明很难找到有关此问题的文档..
最佳答案
在您的初始化中创建一个信息窗口。在您想要打开信息窗口的事件/监听器中,您可以设置内容并在 map 上的标记/位置上打开信息窗口。
// Initialize infowindow
var infowindow = new google.maps.InfoWindow({content: ''});
function add_marker(point, name, content)
{
var marker = new google.maps.Marker({
map: map,
position: point,
dragable: false,
clickable: true,
name: name
});
marker.content = content;
google.maps.event.addListener(marker, 'click', function()
{
infowindow.content = marker.content;
infowindow.open(map, marker);
});
return marker;
};
function addPostCode(zip, html)
{
geocoder.geocode( { 'address': zip}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
map.setCenter(results[0].geometry.location);
var marker = add_marker(results[0].geometry.location, zip, html)
});
});
这个问答帮助我解决了单个或多个信息窗口问题:
关于JavaScript google maps API - 一次打开一个信息窗口..,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3512600/