Skip to content Skip to sidebar Skip to footer

Removing All Controls From A Google Map

I am trying to remove all the controls (zoom, map type drop down, and street view) from my map. There's a method map.removeControl(GControl) but I haven't been able to successfull

Solution 1:

Have you tried this:

http://code.google.com/apis/maps/documentation/javascript/controls.html#DisablingDefaults

functioninitialize() {
  var myOptions = {
    zoom: 4,
    center: new google.maps.LatLng(-33, 151),
    disableDefaultUI: true,
    mapTypeId: google.maps.MapTypeId.ROADMAP  
  }
  var map = new google.maps.Map(document.getElementById("map_canvas"),
       myOptions);
}

Solution 2:

You may see this: google map api by w3schools

As you see in the link, this disables all controls:

var mapOptions = {disableDefaultUI: true}

and the bellow is the options to make them enabled or disabled.

varmapOptions= {
  panControl:true,
  zoomControl:true,
  mapTypeControl:true,
  scaleControl:true,
  streetViewControl:true,
  overviewMapControl:true,
  rotateControl:true
}

Solution 3:

just disableDefaultUI: true

functioninitMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 4,
    center: {lat: -33, lng: 151},
    disableDefaultUI: true
  });
}

Solution 4:

I believe you can create a copy of the GMapUIOptions object and then remove the items you don't want to appear.

From http://code.google.com/apis/maps/documentation/javascript/v2/controls.html#MapUIOptions

"Using the GMapUIOptions Object

The GMapUIOptions object contains a set of properties that specify control placement and UI behavior, which you may modify. For a full set of properties, see the GMapUIOptions reference. Rather than write a GMapUIOptions structure from scratch, you may wish to prepopulate it with the UI behavior available on Google Maps. To do so, use the GMap2.getDefaultUI() method. Once populated, you can modify individual properties to tweak the behavior and initialize the map's UI controls using the GMap2.setUI() method. The following code retrieves the default UI on a "large" map, removes the GScaleControl and resets the map to use the modified UI.

map = new GMap2(document.getElementById("map_canvas"),
    { size: new GSize(400,150) } );
map.setCenter(new GLatLng(41.897997,-87.790203), 11);
var customUI = map.getDefaultUI();
customUI.controls.scalecontrol = false;
map.setUI(customUI);

"

Post a Comment for "Removing All Controls From A Google Map"