Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!
like image 331
Ian Campbell Avatar asked Dec 18 '12 16:12

Ian Campbell


People also ask

How do I remove a default marker from Google Maps?

Open Google Maps. Click Menu ​ Your places Labeled. Next to the label you want to remove, click Remove .

How do I change the marker on Google Maps?

Call the changeMarkerPosition() function and pass the marker object in it. The setPosition() will change the marker position on google map based on the specified latitude and longitude.


2 Answers

Try:

map.setOptions({draggable: true});
like image 82
Marcelo Avatar answered Sep 20 '22 19:09

Marcelo


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
      };
like image 32
Darryl Avatar answered Sep 21 '22 19:09

Darryl