如何使用jQuery隐藏Google Maps Api Markers

前端之家收集整理的这篇文章主要介绍了如何使用jQuery隐藏Google Maps Api Markers前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
您好,这可能是一个非常愚蠢的问题,但我正在努力使标记消失
他们被点击了。标记位于地图上,但是当我点击它时,它没有
做任何事情。我想知道它为什么不起作用。谢谢!
<script type="text/javascript" src="jQuery.js"></script>
  <script type="text/javascript">

  $(document).ready(function(){
      var myOptions = {
        center: new google.maps.LatLng(40.1,-88.2),zoom: 13,mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);

      var myLatlng = new google.maps.LatLng(40.1,-88.2);
      var temp_marker = new google.maps.Marker({
          position: myLatlng,map: map,title:"Hello World!"
        });

      console.log($(temp_marker));
      console.log(temp_marker);

      //temp_marker.click(function(){$(this).hide();});

      $(temp_marker).click(function(){console.log("click is working"); $(this).hide();});
          });
  </script>
</head>
<body>
  <div id="map_canvas" style="width:100%; height:100%"></div>
</body>

解决方法

temp_marker是一个Javascript对象,而不是DOM元素。要将侦听器附加到标记(API将处理要附加到哪个DOM元素的细节以及如何处理),您应该使用Google Maps API自己的事件系统,如:
google.maps.event.addListener(marker,'click',function() {
    marker.setVisible(false); // maps API hide call
  });

他们的文件Google Maps Javascript API v3 – Events

原文链接:https://www.f2er.com/jquery/181644.html

猜你在找的jQuery相关文章