Javascript 如何禁用谷歌地图 V3 上的地点?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7337266/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 01:51:43  来源:igfitidea点击:

How to disable places on google map V3?

javascriptgoogle-maps-api-3

提问by Nazariy

I'm trying to migrate my application to latest version of Google map API and found that Google appends it's own items by default from Google Places directory to the map. It does not look right together with my own records as it creates duplicate items on the map which can be placed in correctly.

我正在尝试将我的应用程序迁移到最新版本的谷歌地图 API,发现谷歌默认将它自己的项目从谷歌地方目录附加到地图。它与我自己的记录看起来不正确,因为它在地图上创建了可以正确放置的重复项目。

Is there an option how to hide this local businesses or to control what is shown and what is not?

是否可以选择如何隐藏此本地企业或控制显示的内容和不显示的内容?

here is sample code:

这是示例代码:

<!DOCTYPE html>
<html>
  <head>
    <title>Google Maps JavaScript API v3 Example: Map Simple</title>
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta charset="UTF-8">
    <style type="text/css">
      html, body, #map_canvas {
        margin: 0;
        padding: 0;
        height: 100%;
      }
    </style>
    <script type="text/javascript"
        src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript">
      var map;
      function initialize() {
        var myOptions = {
          zoom: 16,
          center: new google.maps.LatLng(37.422833333333,25.323166666667),
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById('map_canvas'),
            myOptions);
      }

      google.maps.event.addDomListener(window, 'load', initialize);
    </script>
  </head>
  <body>
    <div id="map_canvas"></div>
  </body>
</html>

As you can see on map, there are few tiny icons, which you can click on and information would appear in bubble. I need to hide this icons or at least disable on click event for this items.

正如你在地图上看到的,有几个小图标,你可以点击它们,信息就会出现在气泡中。我需要隐藏此图标或至少禁用此项目的单击事件。

回答by Pekka

Just a pointer - this seems possible with custom styled maps. If I'm not mistaken, the feature type you're looking for would be poi.business, whose visiblityyou would turn off.

只是一个指针 - 这对于自定义样式的地图似乎是可能的。如果我没记错的话,您要查找的要素类型将是poi.businessvisiblity您将转向谁off

There's a wizardto help you build the options array.

有一个向导可以帮助您构建选项数组。

回答by Kimooz

You can remove it by adding the following code:

您可以通过添加以下代码来删除它:

var styles = [
   {
     featureType: "poi",
     stylers: [
      { visibility: "off" }
     ]   
    }
];

var styledMap = new google.maps.StyledMapType(styles,{name: "Styled Map"});