[英]Restrict google maps API marker to only one click per marker
我正在創建一個簡單的地圖Phonegap應用程序,您可以在其中單擊地圖,並添加一個標記,並顯示一個彈出表單。 這工作正常,但是我需要確保每個標記只能單擊一次。
到目前為止,這是我嘗試過的:
google.maps.event.addListener(clickMarker, 'click',
function (e) {
addLocations(this.getPosition()); // calls popup form
/* clickMarker.setOptions({
clickable: false
});*/
clickMarker.setClickable(false);
});
我要問的可能嗎? 如果可能,我在做什么錯?
將addListener
替換為addListenerOnce
。 這將確保您的偵聽器被調用一次。
否,而不是將clickable設置為false,請嘗試刪除事件偵聽器
clickMarker.addListener('click', //add the listener to your marker object directly
function (e) {
addLocations(this.getPosition()); // calls popup form
// Do ever things you want to do before calling this
// Removing the event, so we can just call once
google.maps.event.clearListeners(clickMarker, "click"); // don't forget the 's'
});
由於您正在使用phonegap,因此強烈建議您將此插件用於Google地圖,這樣會更容易:
https://github.com/wf9a5m75/phonegap-googlemaps-plugin
-卡洛斯:-)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.