I am not able to place markers on the places which is already marked by google with other symbols .

后端 未结 2 421
梦毁少年i
梦毁少年i 2021-01-29 10:04

The info window and marker is not shown for the places which is already marked by google. for example: if you run the code and click anywhere , a marker and a info window will a

2条回答
  •  攒了一身酷
    2021-01-29 11:00

    When you click on such a place(POI) there will no click be triggered on the map.

    When you don't want to hide the POI's, you must trigger the click on your own.

    Possible approach(see: How to get a click event when a user clicks a (business) place on the map )

    //keep a reference to the original setPosition-function
    var fx = google.maps.InfoWindow.prototype.setPosition;
    
    //override the built-in setPosition-method
    google.maps.InfoWindow.prototype.setPosition = function () {
    
      //this property isn't documented, but as it seems
      //it's only defined for InfoWindows opened on POI's
      if (this.logAsInternal) {
        google.maps.event.addListenerOnce(this, 'map_changed',function () {
          var map = this.getMap();
          //the infoWindow will be opened, usually after a click on a POI
          if (map) {
            //trigger the click
            google.maps.event.trigger(map, 'click', {latLng: this.getPosition()});
            //hide the default-infoWindow of the POI
            this.setMap(null);
          }
        });
      }
        //call the original setPosition-method
      fx.apply(this, arguments);
    };
    

    Demo: http://jsfiddle.net/doktormolle/1yrpm98q/

提交回复
热议问题