2012-09-19 33 views
0

我们正在使用Google Maps,并且我们有一个完整填充的地图,里面有很多标记,当点击地图之外的特定结果时,会执行以下代码相应的标记。Google Map InfoBox反复打开/绘制

map.setCenter(new google.maps.Marker({ 
    position : new google.maps.LatLng(latitude, longitude) 
}).getPosition()); 
map.setZoom(10); 
google.maps.event.trigger(currentMarker, 'click', {latLng: new google.maps.LatLng(latitude, longitude)}); 

此代码是为了,中心指定的标记,放大标记,并激活“点击”事件,这反过来又吸引/打开一个信息框。

问题是,当运行此代码的大多数时间点击事件在标记上被触发多次,导致InfoBox重绘多次,但这种情况发生了很多次(每次不是次数)。有没有人有一个想法,为什么这可能会发生?

回答

0

如果您将currentMarker传入google.maps.event.trigger中,我相当肯定您不需要指定纬度/经度。它应该是google.maps.event.trigger(currentMarker, 'click')

同样,另一种选择是在外部链接上使用jquery的.on()事件来检测点击,然后触发标记上的infoWindow.open()。下面是这个样子的一个片段。

$('#openmarker').on('click', function(e){ 
    e.preventDefault(); 
    infowindow.open(map,currentMarker); 
    map.setCenter(currentMarker.getPosition()); 
}); 
相关问题