Link to home
Start Free TrialLog in
Avatar of Yuri Boyz
Yuri BoyzFlag for Uganda

asked on

Disable All controls and buttons in Google Map API version 2

How to disable MAP, Satellite buttons and zoom control on Google map in API version 2.

Here is my code
function initialize()
{
    map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(25.263856, 51.497131), 3);
	
	//map.setOptions {disableDefaultUI:true}; 
	//var mapOptions {disableDefaultUI: true}
       //disableDefaultUI: true


}

Open in new window


The commented lines are not working. I think these are for API version 3.
Avatar of lenamtl
lenamtl
Flag of Canada image

I suggest you to update to v3

On this page you will see the previous and new way with code example:
https://developers.google.com/maps/documentation/javascript/v2tov3

Check if you have anycode similar to this
 map.addControl(new GLargeMapControl());

Open in new window

and comment it.

PS based on your code you are using GMap script
for newer see http://gmap3.net/

for older
http://hpneo.github.io/gmaps/
https://github.com/hpneo/gmaps

Note several dev are now switching to Leaflet  https://leafletjs.com/index.html
Avatar of Yuri Boyz

ASKER

thanks for your comments. LEt me check them.
No I am not using gmaps.js because i am not including it in my code.
I am using Google Maps API 2.  Currently I am unable to hide controls of map.
Try this, this is very old code you should update to the latest version

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Google Maps JavaScript API Example: Simple Map</title>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=AIzaSyD4iE2xVSpkLLOXoyqT-RuPwURN3ddScAI"
            type="text/javascript"></script>
    <script type="text/javascript">

    function initialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(37.4419, -122.1419), 13);
        //map.setUIToDefault();
      }
    }

    </script>
  </head>
  <body onload="initialize()" onunload="GUnload()">
    <div id="map_canvas" style="width: 500px; height: 300px"></div>
  </body>
</html>

Open in new window

Not working. Controls are appearing on it.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.