0

了解 Google Maps APIv3 的工作原理,我使用一个示例来隐藏地图上的标记(https://developers.google.com/maps/documentation/javascript/examples/overlay-remove),所以我尝试添加可拖动的属性,但是在 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>
4

1 回答 1

0

感谢您的关注,我将整个代码复制到一个新文件中并且可以正常工作,我猜原始文件中有一些奇怪的东西。

也许问题出在我一直在使用的钥匙上,我改变了它,一切都变得更好了。

于 2012-08-22T22:39:27.053 回答