Hiding Map Features with Styling

by mathiasfcx

HTML

<div id="map"></div>
<!-- Replace the value of the key parameter with your own API key. -->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initMap">


</script>

CSS

/* Always set the map height explicitly to define the size of the div
 * element that contains the map. */

#map {
  height: 100%;
}


/* Optional: Makes the sample page fill the window. */

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

.map-control {
  background-color: #fff;
  border: 1px solid #ccc;
  box-shadow: 0 2px 2px rgba(33, 33, 33, 0.4);
  font-family: 'Roboto', 'sans-serif';
  margin: 10px;
  padding-right: 5px;
  /* Hide the control initially, to prevent it from appearing
     before the map loads. */
  display: none;
}


/* Display the control once it is inside the map. */

#map .map-control {
  display: block;
}

.selector-control {
  font-size: 14px;
  line-height: 30px;
  vertical-align: baseline;
}

JavaScript

var map;

function initMap() {
  var myLatlng = new google.maps.LatLng(34.04, -118.24);
  var myOptions = {
    zoom: 13,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    styles: [{
      "featureType": "poi",
      "stylers": [{
        "visibility": "off"
      }]
    }, {
      "featureType": "transit.station.bus",
      "stylers": [{
        "visibility": "off"
      }]
    }]
  };
  var map = new google.maps.Map(document.getElementById('map'), myOptions);
}