如何更改地图的Google Maps可拖动属性(而不是标记)?

Ian*_*ell 14 draggable google-maps-api-3


Google Maps v3参考中,我看到有一种方法setDraggable(boolean)可以应用于地图标记.

不过,我想设置setDraggabletrue开启地图,没有在地图上标记.

我已在属性设置draggablefalse在在MapOptions,但我不知道如何设置这true以后......   map.setDraggable(true)不能正常工作:

    // 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!
Run Code Online (Sandbox Code Playgroud)

Mar*_*elo 21

尝试:

map.setOptions({draggable: true});
Run Code Online (Sandbox Code Playgroud)