1

我有许多地图标记,使用完全相同的纬度/长度线,因此无论我放大多远,我的地图仍然显示标记群集和结果数量。使用标记管理器的Google地图信息窗口谷歌地图V3

有没有办法让一些onclick或onhover事件,以便它显示列表中的所有标记在该集群中的信息框?然后点击该信息框中的链接打开个人标记信息框?

我已经读过解决方案来改变经纬度,只需少量,以使它们不在同一位置。我认为这是非常混乱的,不管怎么说,如果最终在同一个位置出现多个标记10+,反正不是那么好。我认为用户只需点击群集并调出带有链接的所有标记的信息窗口会容易得多。

或者,如果有人知道另一个做我正在寻找的插件,我也可以使用它。我只是没有找到关于它的很多信息。

回答

1

可能有一个插件可以做你想做的事,但也可以没有一个做。我在其中一个项目中做了类似的事情。

  1. 将事件监听器添加到每个标记;点击打开标记列表信息窗口
  2. 标记列表信息窗口的内容包含将打开标记信息窗口的onclick属性。

我的代码被藏到的功能,但它基本上只是这样的:

//1) while creating marker, create click listener that opens the marker list 
google.maps.event.addListener(marker, 'click', function() { 
    markerWindow.close(); 
    markerList.open(map, marker); 
}); 

//2) store the content required by the marker's info windows 
var markers = [ 
    [marker1Reference, "The Stadium"], 
    [maerker2Reference, "The Supermarket"] 
]; 

//3) the function that is called each time a marker is chosen from the marker list 
function openMarkerInfo(markerIndex) { 
    markerList.close(); 
    markerWindow.setContent(markers[markerIndex][1]); 
    markerWindow.open(map, markers[markerIndex][0]); 
} 

//4) info window for the marker list - the content includes JS onclick events that will open each marker info window 
markerList = new google.maps.InfoWindow({ 
    content: "Choose:<br><br><div href='' class='markerLink' onclick='openMarkerInfo(0)'>The Stadium</div><br><div href='' class='markerLink' onclick='openMarkerInfo(1)'>My House</div>" 
}); 
//5) the marker window that will get set each time a marker is clicked in the list 
markerWindow = new google.maps.InfoWindow(); 

希望帮助!