【问题标题】:how to disable click event on marker after single click单击后如何禁用标记上的单击事件
【发布时间】:2016-11-01 00:05:00
【问题描述】:

单击标记后,我想:

  1. 禁用地图上的点击事件
  2. 等待 5 秒
  3. 在地图上重新启用点击事件 我使用 ajax 和 setInterval 3 秒 这是我的代码:

    详细信息 = 新 google.maps.LatLng(18.60301515,73.79623622); bindInfoWindow(标记,地图,信息窗口,详细信息);

    function bindInfoWindow(marker, map, infoWindow, description) {

    google.maps.event.addListener(marker,'click', function() {
        var geocoder =  new google.maps.Geocoder();
    
        geocoder.geocode({ 'latLng': description }, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                if (results[1]) {
                    var location1=results[1].formatted_address;
                    // set content to marker at click event
                    infoWindow.setContent('Location:'+location1+'<br>');
                }
            }
        });
        infoWindow.open(map, marker);
    });
    

    }

谢谢

【问题讨论】:

  • 投反对票。与同一用户的其他答案重复

标签: javascript php ajax


【解决方案1】:

我会这样做:

JavaScript

details = new google.maps.LatLng(18.60301515,73.79623622);
bindInfoWindow(marker, map, infoWindow , details);  
var allowClick = true;

function bindInfoWindow(marker, map, infoWindow, description) {
  google.maps.event.addListener(marker,'click', function() {
    if(allowClick) {
      allowClick = false;

      var geocoder =  new google.maps.Geocoder();
      geocoder.geocode({ 'latLng': description }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
          if (results[1]) {
            var location1=results[1].formatted_address;    
            infoWindow.setContent('Location:'+location1+'<br>');
          }
        }
      });
      infoWindow.open(map, marker);

      setTimeout(function() { allowClick = true; }, 5000);
    }
  });
} 

【讨论】:

  • 我使用您的代码单击禁用 n 启用问题已解决,但更改纬度 n 经度后位置未更新。换点后地址也必须改,请帮忙
  • @user5209761 这听起来像是一个不同的问题?如果是这样,请发布另一个问题。
【解决方案2】:

您可以使用标志(全局值)。和一个 Settimer 在 5 秒后更改标志的值。

details = new google.maps.LatLng(18.60301515,73.79623622);
bindInfoWindow(marker, map, infoWindow , details);  
 var flag_timer=true;
function bindInfoWindow(marker, map, infoWindow, description) {

      google.maps.event.addListener(marker,'click', function() {
         if(flag_timer===true){
         var geocoder =  new google.maps.Geocoder();

         geocoder.geocode({ 'latLng': description }, function (results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                if (results[1]) {
                   var location1=results[1].formatted_address;    
         infoWindow.setContent('Location:'+location1+'<br>');      // set content to marker at click event


                }
            }
        });
        infoWindow.open(map, marker);
         flag_timer=false;
        setTimeout(function() { flag_timer = true; }, 5000);
     }
  });


}     

【讨论】:

  • 我使用您的代码单击禁用 n 启用问题已解决,但更改纬度 n 经度后位置未更新。换点后地址也必须改,请帮忙
  • @user5209761你能显示完整的代码吗?我没有看到任何与更新地址相关的内容?
  • @Arg0n 当我看到这个问题时,我就想到了这个想法并使其可用。发布后我才看到你的代码。
猜你喜欢
  • 2012-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-06
  • 2020-02-17
  • 2023-03-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多