【问题标题】:Remove existing labels from google map从谷歌地图中删除现有标签
【发布时间】:2015-11-16 16:43:21
【问题描述】:

当在地图上绘制纬度和经度时,我有一个使用谷歌地图构建的应用程序有没有办法删除地图中已经存在的标记

【问题讨论】:

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


【解决方案1】:

<!DOCTYPE html>
<html>
  <head>
    <style type="text/css">
      html, body { height: 100%; margin: 0; padding: 0; }
      #map { height: 100%; }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <script type="text/javascript">

var map;
function initMap() {
  map = new google.maps.Map(document.getElementById('map'), {
    center: {lat: 42.367112, lng: -71.080964},
    zoom: 16,
    styles: [
      {
        "featureType": "poi",
        "stylers": [
          { "visibility": "off" }
        ]
      }
    ]
  });
}

    </script>
    <script async defer
      src="https://maps.googleapis.com/maps/api/js?callback=initMap">
    </script>
  </body>
</html>

只需转到 Google 地图样式向导,然后关闭兴趣点可见性,然后将 JSON 用于您的地图样式。

在您的地图构造函数中,指定:

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

【讨论】:

    【解决方案2】:

    是的,这可以在 Google Maps API 中使用以下代码。

    [
        {
            featureType: 'all',
            elementType: 'labels',
            stylers: [{ 
                visibility: 'off' 
             }]
         }
    ]
    

    另请查看StyleWizard,了解有关设置地图样式的所有信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-10
      • 2015-04-09
      • 2019-06-20
      • 2012-10-17
      • 1970-01-01
      • 2013-09-29
      相关资源
      最近更新 更多