2012-12-18 23 views
14


Google Maps v3 reference,我看到有一種方法setDraggable(boolean)可以應用到地圖標記。

不過,我想設置setDraggabletrue在地圖上標記的地圖上。

我已經財產draggable設置爲在MapOptions false,但我不知道如何稍後設置爲true ...   map.setDraggable(true)工作:

如何更改地圖的Google Maps可拖動屬性(不是標記)?

// object literal for map options 
    var myOptions = 
    { 
     center: new google.maps.LatLng(37.09024, -95.712891), 
     zoom: 4, // smaller number --> zoom out 
     mapTypeId: google.maps.MapTypeId.TERRAIN, 

     // removing all map controls 
     disableDefaultUI: true, 

     // prevents map from being dragged 
     draggable: false, 

     // disabling all keyboard shortcuts 
     keyboardShortcuts: false, 

     disableDoubleClickZoom: true, 

     // do not clear the map div  
     noClear: true 
    }; 

    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 

    map.setDraggable(true); // does NOT work! 

回答

20

嘗試:

map.setOptions({draggable: true}); 
+0

感謝@Marcelo,該訣竅!我並不知道'setOptions',以這種方式訪問​​地圖選項是多麼容易。 –

+0

@Marcelo,非常感謝你! –

1

我在這一部分輸入了我的代碼,它和我在移動設備和臺式機上使用

function initialize() 
    { 
    var mapProp = { 
     center:myCenter, 
     zoom:5, 
     draggable:false, 
     mapTypeId:google.maps.MapTypeId.ROADMAP 
     }; 
0

setDraggable未在Map類中使用。

它在使用:

標記類
折線類
Polygon類
Rectangle類並在Circle類

在你的情況,你可以簡單地使用:

map.draggable = true; 
相關問題