Remove options from Google Maps

Asked

Viewed 121 times

0

I’m using the Google Maps and would like to take away all other options (restaurants, churches, schools, posts, etc.) and leave only my markers

Currently I start the map like this:

function initMap( lat, lng, nome, lojas  ) {
        var myLatLng = {lat, lng};
        var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 16,
          center: myLatLng
        });

        var marker = new google.maps.Marker({
          position: myLatLng,
          map: map,
          title: nome
        });
     }

inserir a descrição da imagem aqui

1 answer

1


Try to add that:

var styles = {
    default: null,
    hide: [
      {
        featureType: 'poi.business',
        stylers: [{visibility: 'off'}]
      },
      {
        featureType: 'transit',
        elementType: 'labels.icon',
        stylers: [{visibility: 'off'}]
      }
    ]
  }; //Aqui você define o estilo na qual os ícones ficam invisíveis

map.setOptions({styles: styles['default']}); //Aqui você aplica o estilo ao seu mapa

Taken from Google’s own documentation: https://developers.google.com/maps/documentation/javascript/examples/hiding-features

In your code would look like this:

var styles = {
        default: null,
        hide: [
            {
            featureType: 'poi.business',
            stylers: [{visibility: 'off'}]
        },
        {
        featureType: 'transit',
        elementType: 'labels.icon',
        stylers: [{visibility: 'off'}]
      }
    ]
  }; 

function initMap( lat, lng, nome, lojas  ) {
    var myLatLng = {lat, lng};
    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 16,
      center: myLatLng
    });

  map.setOptions({styles: styles['hide']});

    var marker = new google.maps.Marker({
      position: myLatLng,
      map: map,
      title: nome
    });
 }

Access all the featureType at the following link: https://developers.google.com/maps/documentation/javascript/style-reference#style-Features

  • In case I changed 'default' to 'Hide' map.setOptions({styles: styles['hide']});

  • Where do I find this list? Like a featureType: 'poi.business', ?

  • 1

    @adventistaam looks at the end of the question, I edited ;)

  • Excellent! Thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.