删除谷歌地图中的按钮

时间:2018-04-10 01:05:52

标签: javascript jquery google-maps google-maps-api-3

我想问一下你是否能够删除谷歌地图中的其他按钮。这可能吗?如何删除视图全屏按钮,Google按钮,其他按钮等按钮。请参阅附件图片以供参考。我想删除被环绕的按钮。 enter image description here 这是我的代码。

  <body>
    <div id="map"></div>
    <script>
        function initMap() {
        var map = new google.maps.Map(document.getElementById('map'), {
          center: new google.maps.LatLng(12.8797, 121.7740),
          zoom: 7
        });
        var infoWindow = new google.maps.InfoWindow;

          // Change this depending on the name of your PHP or XML file
          downloadUrl('phpsqlajax_genxml.php', function(data) {
            var xml = data.responseXML;
            var markers = xml.documentElement.getElementsByTagName('marker');
            Array.prototype.forEach.call(markers, function(markerElem) {
              var id = markerElem.getAttribute('id');
              var name = markerElem.getAttribute('name');
              var address = markerElem.getAttribute('address');
              var image = markerElem.getAttribute('image');
              var point = new google.maps.LatLng(
                  parseFloat(markerElem.getAttribute('lat')),
                  parseFloat(markerElem.getAttribute('lng')));

              var infowincontent = document.createElement('div');
              var strong = document.createElement('strong');
              strong.textContent = name
              infowincontent.appendChild(strong);
              infowincontent.appendChild(document.createElement('br'));
              var text = document.createElement('text');
              text.textContent = address
              infowincontent.appendChild(text);
              var marker = new google.maps.Marker({
                map: map,
                position: point,
                icon: 'images.png',
                label: icon.label
              });
              marker.addListener('mouseover', function() {
                infoWindow.setContent(infowincontent);
                infoWindow.open(map, marker);
              });
            });
          });
        }

      function downloadUrl(url, callback) {
        var request = window.ActiveXObject ?
            new ActiveXObject('Microsoft.XMLHTTP') :
            new XMLHttpRequest;

        request.onreadystatechange = function() {
          if (request.readyState == 4) {
            request.onreadystatechange = doNothing;
            callback(request, request.status);
          }
        };

        request.open('GET', url, true);
        request.send(null);
      }

      function doNothing() {}
    </script>
    <script async defer
    src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDi8lFpro0lfLobsw2peldzGqzO6jocT00&callback=initMap">
    </script>
  </body>

3 个答案:

答案 0 :(得分:3)

您可以按照Fenrir的建议设置disableDefaultUI: true,但根据Terms of Service

禁止删除徽标
  

不得删除,隐藏或更改服务条款,链接或   所有权声明。你不会:删除,隐藏或改变   任何Google服务条款或这些条款的任何链接或通知,   或任何版权,商标或其他所有权声明;要么   伪造或删除任何作者归属,法律声明或其他   材料来源或来源的标签。

答案 1 :(得分:2)

功能initMap()添加disableDefaultUI: true

中的

function initMap() {
    var map = new google.maps.Map(document.getElementById('map'), {
    center: new google.maps.LatLng(12.8797, 121.7740),
    zoom: 7,
    disableDefaultUI: true
});

Disabling the default UI

中的更多信息

虽然不删除底部的谷歌按钮。

答案 2 :(得分:2)

您可以像这样单独设置控件。

function initMap() {
    var map = new google.maps.Map(document.getElementById('map'), {
        center: new google.maps.LatLng(12.8797, 121.7740),
        zoom: 7,
        scaleControl: false,
        streetViewControl: false,
        fullscreenControl: false
    });
}