如何从谷歌地图中删除建筑物名称和街道名称

时间:2015-04-12 02:49:23

标签: javascript google-maps

我想从我的谷歌地图中删除街道和建筑物的名称,我认为它应该看起来像这样,但我不知道该把它放在哪里。 https://jsfiddle.net/russiandobby/jyppxbqb/2/

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

1 个答案:

答案 0 :(得分:0)

根据documentation,有两种方法可以设置地图的样式:

  

要修改默认地图类型的样式(标签和道路的更改也会影响地形和卫星地图),请在构建时或通过调用setOptions在地图的MapOptions中设置样式数组。 / p>

  1. 在构建时在地图MapOptions中设置样式数组:
  2. var map = new google.maps.Map(document.getElementById('map-canvas'), {
        disableDoubleClickZoom: true,
        scrollwheel: false,
        navigationControl: false,
        mapTypeControl: false,
        scaleControl: false,
        draggable: false,
        zoom: 17,
        center: new google.maps.LatLng(34.239415, -118.529339),
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        styles: [{
            "featureType": "poi",
                "stylers": [{
                "visibility": "off"
            }]
        }, {
            "featureType": "landscape",
                "stylers": [{
                "visibility": "off"
            }]
        }, {
            "featureType": "transit",
                "stylers": [{
                "visibility": "off"
            }]
        }]
    
    });
    

    updated fiddle

    1. 通过调用setOptions
    2. var styles = [{
          "featureType": "poi",
              "stylers": [{
              "visibility": "off"
          }]
      }, {
          "featureType": "landscape",
              "stylers": [{
              "visibility": "off"
          }]
      }, {
          "featureType": "transit",
              "stylers": [{
              "visibility": "off"
          }]
      }];
      map.setOptions({styles: styles});
      

      updated fiddle