2
當創建像這樣我的Google map markers,添加監聽
我添加事件監聽器 -
var infowindow = new google.maps.InfoWindow({
content: 'Hi there from Alabama!'
});
google.maps.event.addListener(marker, 'mouseover', function() {
infowindow.open(map, marker); // this displays the infowindow on mouseover
});
google.maps.event.addListener(marker, 'mouseout', function() {
infowindow.close(); // this close the infowindow on mouseout
});
marker.addListener('click', function() {
google.maps.event.clearListeners(marker, 'mouseout');
// this removes the mouseout listener when the marker is clicked so that it stays
// present after mouseout.
});
上述作品一種享受,但是我也希望能夠重新 - 在信息窗口關閉後添加mouseout
事件。
我試過新增這給我的功能 -
google.maps.event.addListener(infowindow, 'closeclick', function() {
google.maps.event.addListener(marker, 'mouseout');
// when the info window is closed the mouseout event is reinstated
// I also previously added an alert here to make sure it was hit!
});
這將創建標記好了,但是在行動上,我可以點擊標記>鼠標移出和信息窗口保持目前>關閉infowindow。所有需要的行爲。
但是再次懸停在標記信息窗口顯示(如預期),但在碰到mouseout
事件,我得到 -
JavaScript runtime error: Unable to get property 'apply' of undefined or null reference
該錯誤是居住在谷歌API的JS文件,所以它是非常很難確定問題的根源在哪裏。如何正確地恢復mouseout
事件infowindow
關閉?
亞瑟,好答案,我完全理解我們的邏輯,然而遺憾的是(甚至更具體減速)我仍然得到相同的未定義錯誤鼠標,任何其他想法? – Ebikeneser