拖动时标记在IExplorer上重复

时间:2012-08-21 21:24:39

标签: google-maps google-maps-api-3

了解Google Maps APIv3的工作原理,我使用一个示例在地图上隐藏和隐藏标记(https://developers.google.com/maps/documentation/javascript/examples/overlay-remove),所以我尝试添加draggable属性,但在IExplorer 9上,当标记移动到另一个地方,它后面会产生另一个标记,我不想要它,有什么想法会发生吗?

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
    <style type="text/css">  
      html { height: 100% }  
      body { height: 100%; margin: 0px; padding: 0px }  
      #map_canvas { height: 100% }
    </style>
    <script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script>
    <script>
      var map;
      var markers = [];

      function initialize() {
        var haightAshbury = new google.maps.LatLng(23.886419417295673, -101.86367187500001);
        var mapOptions = {
          zoom: 5,
          center: haightAshbury,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById('map-canvas'),
            mapOptions);

        google.maps.event.addListener(map, 'click', function(event) {
          addMarker(event.latLng);
        });
      }
      // Add a marker to the map and push to the array.
      function addMarker(location) {
        marker = new google.maps.Marker({
          'position': location,
          'draggable':true,     ////// HERE /////
          map: map
        });
        markers.push(marker);
        }

      // Sets the map on all markers in the array.
      function setAllMap(map) {
        for (var i = 0; i < markers.length; i++) {
          markers[i].setMap(map);
        }
      }

      // Removes the overlays from the map, but keeps them in the array.
      function clearOverlays() {
        setAllMap(null);
      }

      // Shows any overlays currently in the array.
      function showOverlays() {
        setAllMap(map);
      }

      // Deletes all markers in the array by removing references to them.
      function deleteOverlays() {
        clearOverlays();
        markers = [];
      }

      google.maps.event.addDomListener(window, 'load', initialize);
    </script>
  </head>
  <body>
    <div id="map-canvas" style="width:100%; height:100%"></div>
  </body>
</html>

1 个答案:

答案 0 :(得分:0)

感谢您的兴趣,我将整个代码复制到一个新文件中并且有效,我猜原始文件中有些奇怪。

也许问题在于我一直在使用的密钥,我改变了它,一切都运行得更好。