-1

我在地图上使用绘图工具。我按照文档中的说明设置了此选项:

  markerOptions: {
    animation: google.maps.Animation.DROP,
    icon: new google.maps.MarkerImage('http://maps.google.com/mapfiles/ms/icons/yellow-dot.png'),
    draggable: true,
    flat: true,
    raiseOnDrag: true
  },

但是,我无法拖动我的标记,并且 DROPE 动画似乎有一个错误但可以工作(在下降前闪烁)。getDraggable 方法返回 true :

  if (event.type == google.maps.drawing.OverlayType.MARKER) {
     markersArray.push(event.overlay);
     alert(event.overlay.getDraggable()); // true
  }

当我单击我的标记时,它会忽略它并改为拖动地图。我该如何解决这个问题?

谢谢

4

1 回答 1

1

这段代码怎么样。这段代码对我有用。

<!DOCTYPE html>
<html>
  <head>
    <title>Google Maps JavaScript API v3 Example: Drawing Tools Library</title>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <link href="https://google-developers.appspot.com/maps/documentation/javascript/examples/default.css" rel="stylesheet">
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=drawing"></script>
    <script>
      function initialize() {
        var mapOptions = {
          center: new google.maps.LatLng(-34.397, 150.644),
          zoom: 8,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };

        var map = new google.maps.Map(document.getElementById('map_canvas'),
          mapOptions);

        var drawingManager = new google.maps.drawing.DrawingManager({
          drawingMode: google.maps.drawing.OverlayType.MARKER,
          drawingControl: true,
          drawingControlOptions: {
            position: google.maps.ControlPosition.TOP_CENTER,
            drawingModes: [
              google.maps.drawing.OverlayType.MARKER
            ]
          },
          markerOptions: {
            animation: google.maps.Animation.DROP,
            icon: new google.maps.MarkerImage('http://maps.google.com/mapfiles/ms/icons/yellow-dot.png'),
            draggable: true,
            flat: true,
            raiseOnDrag: true
          }
        });
        drawingManager.setMap(map);
      }

      google.maps.event.addDomListener(window, 'load', initialize);
    </script>
  </head>
  <body>
    <div id="map_canvas"></div>
  </body>
</html>
于 2012-11-28T22:39:18.743 回答