Changes clickable of marker

Marker clickable = true

Description

Sometimes you want to control click event acceptable of marker. You can turn on / turn off using Marker.setClickable(true or false), or Marker.setOptions({ clickable : true or false}).

<script type='text/javascript'>

    var mapCanvas;
    function intialize() {
      //Create a map
      var initPos = new google.maps.LatLng(40.803, -74.097);
      mapCanvas = new google.maps.Map(document.getElementById("map_canvas"));
      mapCanvas.setCenter(initPos);
      mapCanvas.setZoom(9);
      mapCanvas.setMapTypeId(google.maps.MapTypeId.ROADMAP);
      
      var infoWnd = new google.maps.InfoWindow({
        content :  "Please change the checkbox below."
      });
      
      var marker = new google.maps.Marker({
        position : initPos,
        map : mapCanvas,
        clickable : true
      });
      infoWnd.open(null, marker);
      
      var checkbox = document.getElementById("marker_clickable");
      google.maps.event.addDomListener(checkbox, "click", function(){
        marker.setClickable(checkbox.checked);
      });
  
      google.maps.event.addListener(marker, "click", function() {
        alert("clicked!");
        infoWnd.setContent("clicked!");
        infoWnd.open(mapCanvas, marker);
      });
      google.maps.event.addListener(marker, "clickable_changed", function() {
        infoWnd.close();
      });
    }
    google.maps.event.addDomListener(window, "load", intialize);
  </script>





Search
Books
Google Maps API Programming Guide

Four Google Maps API Experts wrote this book. Introducing useful examples for developers!
See more details