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 に答える