简体   繁体   中英

how to disable click event after single click on marker n enable after few seconds

how to disable marker click event after single click and enable after few sec This is my code

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;    
             infoWindow.setContent('Location:'+location1+'<br>');      // set content to marker at click event


                    }
                }
            });
         infoWindow.open(map, marker);    

      });
     } 

Thanks

You didn't attache HTML code, so I cannot answer you how to disable to button itself, but there is a code to prevent logic from be excuted:

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

  if (bindInfoWindow.prototype.Enable === undefined || bindInfoWindow.prototype.Enable==true){
      bindInfoWindow.prototype.Enable =false;
      setTimeout(function enableFunc(){
           bindInfoWindow.prototype.Enable =true;
      }, 3000);

      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;    
         infoWindow.setContent('Location:'+location1+'<br>');      // set content to marker at click event


                }
            }
        });
     infoWindow.open(map, marker);    

  });
}
 } 

use settimeout function on your click event function set time how long you waiting after click. revised your code

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

          google.maps.event.addListener(marker,'click', function() {

            setTimeout(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;    
                     infoWindow.setContent('Location:'+location1+'<br>');      // set content to marker at click event
                            }
                        }
                    });
                 infoWindow.open(map, marker);  
           }, 3000); // set time how long waiting
      });
 }

hope it works

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM