2012-11-28 104 views
0

我正在使用繪圖工具和我的地圖。我這個文件中說明的選項設置:可拖動標記和繪圖工具

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 
    } 

當我點擊我的標記,它忽略它,它拖動地圖來代替。我怎麼能解決這個問題?

謝謝

回答

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> 
+0

哇! 它不適合我,我不能拖動項目,如果你可以和相同的閃光燈出現...任何人有這個問題? 我正在使用Chrome和WampServer 2:/ –

+0

真的嗎?!這段代碼從Google官方示例代碼中稍微改變了一些。你嘗試過其他瀏覽器嗎? – wf9a5m75

+0

然後在Chrome中按[Ctrl] + [Shift] + [I],然後打開Goog​​le Developer Console。有沒有錯誤信息? – wf9a5m75