disable clickable landmark on google map

后端 未结 6 638
粉色の甜心
粉色の甜心 2020-12-03 06:56

I\'m using google map API v3. I want to disable click action on default google landmark/poi. For example, when I zoom to UCLA, the school icon shows up (that\'s fine) but I

6条回答
  •  一向
    一向 (楼主)
    2020-12-03 07:45

    I encountered this same problem. Google appears to have recently changed their api to make the base map labels "clickable" and there is not yet a simple API call to disable their clickablility. http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/f1ac9ad4da3606fe

    I would like to see google add a simple map option like this, but alas it doesn't exist yet

    var opts = { clickableLabels:false };
    var map = new maps.google.com.map(div,opts);
    

    The following solution works, but because it relies on custom styled map tiles, free maps are limited to (2,500 maps loads per day) - See Google Maps FAQ.

    function initialize() {
    
      // For more details see 
    // http://code.google.com/apis/maps/documentation/javascript/styling.html
      var noPOILabels = [
        { 
          featureType: "poi", 
          elementType: "labels", 
          stylers: [ { visibility: "off" } ] 
    
        }
      ];
    
      // Create a new StyledMapType object, passing it the array of styles,
      // as well as the name to be displayed on the map type control.
      var noPOIMapType = new google.maps.StyledMapType(noPOILabels,
        {name: "NO POI"});
    
      // Create a map object, and include the MapTypeId to add
      // to the map type control.
      var mapOptions = {
        zoom: 11,
        center: new google.maps.LatLng(55.6468, 37.581),
        mapTypeControlOptions: {
          mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'no_poi']
        }
      };
      var map = new google.maps.Map(document.getElementById('map_canvas'),
        mapOptions);
    
      //Associate the styled map with the MapTypeId and set it to display.
      map.mapTypes.set('no_poi', noPOIMapType);
      map.setMapTypeId('no_poi');
    }
    

提交回复
热议问题