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

前端 未结 7 798
忘掉有多难
忘掉有多难 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:13

    We can do it by handling clicks on poi, Google api has provided a way to detect clicks on POI as per this article

    Based on article above Here is a simpler version of code that can be used to stop the clicks on POI

    function initMap() {
        map = new google.maps.Map(document.getElementById('map'), myOptions);
        var clickHandler = new ClickEventHandler(map, origin);
    }
    
    
    var ClickEventHandler = function (map, origin) {
        this.origin = origin;
        this.map = map;
        this.map.addListener('click', this.handleClick.bind(this));
    };
    
    ClickEventHandler.prototype.handleClick = function (event) {
        //console.log('You clicked on: ' + event.latLng);
        if (event.placeId) {
            //console.log('You clicked on place:' + event.placeId);
            // Calling e.stop() on the event prevents the default info window from
            // showing.
            // If you call stop here when there is no placeId you will prevent some
            // other map click event handlers from receiving the event.
            event.stop();
    
        }
    }
    
    0 讨论(0)
提交回复
热议问题