Skip to content
Advertisement

How do I hide labels in styled map of Philipines?

I have the problem with Philipines`s view at map:

enter image description here enter image description here

Map styles:

     var styles = [
           {"stylers": [{ "visibility": "off" }]},
           {
               "featureType": "administrative",
               "elementType": "geometry.stroke",
               "stylers": [
                   {
                       "visibility": "on"
                   },
                   {
                       "color": "#ffffff"
                   },
                   {
                       "weight": 1
                   }
               ]
           },
           {
                featureType: "administrative.province",
                elementType: "geometry",
                stylers: [
                    { visibility: "off" }
                ]
           },
           {
               featureType: "administrative.country",
               elementType: "labels",
               stylers: [
                   { visibility: "off" }
               ]
           },
           {
               "featureType": "landscape",
               "elementType": "all",
               "stylers": [
                   {
                       "visibility": "on"
                   },
                   {
                       "color": "#a2d39c"
                   }
               ]
           },
           {
               "featureType": "water",
               "elementType": "all",
               "stylers": [
                   {
                       "visibility": "on"
                   },
                   {
                       "color": "#0e76bc"
                   }
               ]
           }
       ];

All fine,except Philipines with strange “titles” on it. I haven`t any ideas…

Advertisement

Answer

I see “Spratty Islands”, “Paracel Islands”. You need to turn off:

{
  "featureType": "landscape.natural",
  "elementType": "labels",
  "stylers": [
    { "visibility": "off" }
  ]
}

proof of concept fiddle

code snippet:

var geocoder;
var map;

function initialize() {
  var map = new google.maps.Map(
    document.getElementById("map_canvas"), {
      center: new google.maps.LatLng(37.4419, -122.1419),
      zoom: 13,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      styles: styles
    });
  geocoder = new google.maps.Geocoder();
  geocoder.geocode({
    'address': "Philipines"
  }, function(results, status) {
    if (status === google.maps.GeocoderStatus.OK) {
      map.fitBounds(results[0].geometry.bounds);
    } else {
      alert('Geocode was not successful for the following reason: ' + status);
    }
  });

}
google.maps.event.addDomListener(window, "load", initialize);

var styles = [{
  "stylers": [{
    "visibility": "off"
  }]
}, {
  "featureType": "administrative",
  "elementType": "geometry.stroke",
  "stylers": [{
    "visibility": "on"
  }, {
    "color": "#ffffff"
  }, {
    "weight": 1
  }]
}, {
  featureType: "administrative.province",
  elementType: "geometry",
  stylers: [{
    visibility: "off"
  }]
}, {
  featureType: "administrative.country",
  elementType: "labels",
  stylers: [{
    visibility: "off"
  }]
}, {
  "featureType": "landscape",
  "elementType": "all",
  "stylers": [{
    "visibility": "on"
  }, {
    "color": "#a2d39c"
  }]
}, {
  "featureType": "water",
  "elementType": "all",
  "stylers": [{
    "visibility": "on"
  }, {
    "color": "#0e76bc"
  }]
}, {
  "featureType": "landscape.natural",
  "elementType": "labels",
  "stylers": [{
    "visibility": "off"
  }]
}];
html,
body,
#map_canvas {
  height: 100%;
  width: 100%;
  margin: 0px;
  padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
<div id="map_canvas"></div>
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement