Disable point-of-interest information window using Google Maps API v3

前端 未结 7 801
忘掉有多难
忘掉有多难 2020-12-08 04:43

I have a custom map with an information bubble and custom markers. When I zoom into points of interest such as parks and universities appear and when I click an information

7条回答
  •  轮回少年
    2020-12-08 05:04

    See the other answers for the clickable: false answer.

    However, if you want it clickable, but no infowindow, call stop() on the event to prevent the infowindow from showing, but still get the location info:

    map.addListener('click', function (event) {
      // If the event is a POI
      if (event.placeId) {
    
        // Call event.stop() on the event to prevent the default info window from showing.
        event.stop();
    
        // do any other stuff you want to do
        console.log('You clicked on place:' + event.placeId + ', location: ' + event.latLng);
      }
    }
    

    For more info, see the docs.


    Other option: completely remove the POI-icons, and not only the infoWindow:

    var mapOptions = {
      styles: [{ featureType: "poi", elementType: "labels", stylers: [{ visibility: "off" }]}]
    };
    var map = new google.maps.Map(document.getElementById('map-canvas'),
        mapOptions);
    

提交回复
热议问题