Ian Campbell
Ian Campbell

Reputation: 2748

How do I change the Google Maps draggable property for the map (not the marker)?


In the Google Maps v3 reference, I see there is a method setDraggable(boolean) which can be applied to a map marker.

However, I want to set setDraggable to true on the map, not on a map marker.

I have set the property draggable to false in the mapOptions, but I don't know how to set this to true later...  map.setDraggable(true) does not work:

    // 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!

Upvotes: 15

Views: 31900

Answers (3)

gadlol
gadlol

Reputation: 1353

setDraggable is not used in the Map class.

It is used in the:

Marker Class,
Polyline class,
Polygon class,
Rectangle class and in the Circle class.

In your case you can simply use:

map.draggable = true;

Upvotes: 0

Darryl
Darryl

Reputation: 11

I entered my code in this section and it worked on mobile and desktop

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

Upvotes: 1

Marcelo
Marcelo

Reputation: 9407

Try:

map.setOptions({draggable: true});

Upvotes: 25

Related Questions