我有一個功能gmap,當我點擊標記時顯示標記並顯示infowindows。 現在,我想在懸停與該標記相關的列表項目時顯示一個infowindow。我測試了很多東西,但infowindow從不顯示。Google map api v3 show infowindows當點擊一個外部元素時
我的項目都是這樣的<li class="shop" data-shop="markerId">
而我的JS:
function initShopsMap(shops, myLatlng) {
createMap('map-canvas', myLatlng);
var infoWindow = new google.maps.InfoWindow();
for (var i = 0, length = shops.length; i < length; i++) {
var data = shops[i],
latLng = new google.maps.LatLng(data.latitude, data.longitude);
// Creating a marker and putting it on the map
var marker = new google.maps.Marker({
position: latLng,
map: map,
id: data.id,
name: data.name,
slug: data.slug,
infoWindow: infoWindow
});
(function(marker) {
// Attaching a click event to the current marker
google.maps.event.addListener(marker, 'click', function(e) {
infoWindow.setContent(marker.name + ' ' + marker.slug);
infoWindow.open(map, marker);
});
//hover list item when hover a marker
google.maps.event.addListener(marker, 'mouseover', function(e) {
//todo scroll to
$('.shop[data-shop="'+marker.id+'"]').addClass('active');
});
google.maps.event.addListener(marker, 'mouseout', function(e) {
$('.shop[data-shop="'+marker.id+'"]').removeClass('active');
});
})(marker, data);
}
}
如何將事件添加到$('.shop[data-shop="'+marker.id+'"]')
,顯示相關信息窗口?
編輯:用google.maps.event.trigger(markers[myPoint-1], "click");
解決的問題與IIFE
google.maps.event.trigger(標記[myPoint-1], 「點擊」)工作;做的伎倆 – Tib 2013-03-06 12:38:36