【问题标题】:How do I change the Google Maps draggable property for the map (not the marker)?如何更改地图(而不是标记)的 Google Maps 可拖动属性?
【发布时间】:2012-12-05 21:19:18
【问题描述】:


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

但是,我想在 ma​​p 上将 setDraggable 设置为 truenot 在地图标记上。

我已在 mapOptions 中将属性 draggable 设置为 false,但我不知道稍后如何将其设置为 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!

【问题讨论】:

    标签: google-maps-api-3 draggable


    【解决方案1】:

    试试:

    map.setOptions({draggable: true});
    

    【讨论】:

    【解决方案2】:

    我在本节中输入了我的代码,它可以在移动设备和桌面设备上运行

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

    【讨论】:

      【解决方案3】:

      setDraggable 未在 Map 类中使用。

      用于:

      标记类
      折线类
      多边形类
      矩形类 并在 Circle 类中。

      在你的情况下,你可以简单地使用:

      map.draggable = true;
      

      【讨论】:

        猜你喜欢
        • 2010-12-28
        • 2011-03-19
        • 2011-08-22
        • 2016-12-25
        • 2017-10-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-11
        相关资源
        最近更新 更多