Google地图,无法从实例化外部到达信息窗口

时间:2018-11-01 05:59:36

标签: javascript reactjs google-maps onclick infowindow

大家好,我在边栏上的列表项中遇到与点击事件有关的问题 当我尝试在其中使用infowindow时,问题与istEntryClick函数有关,该应用程序崩溃了。 我试图在没有信息窗口的情况下登录该功能,以检查控制台是否显示了我单击的正确条目,并且确实确定了。 这是我正在执行的相关代码段:

renderMap = () => {
    loadScript("https://maps.googleapis.com/maps/api/js?key='')
    window.initMap = this.initMap
  }

// instantiate map

  initMap = () => {
       const map = new 
       window.google.maps.Map(document.getElementById('map'), {
         center: {lat:, lng:},
         zoom: 8
       })

       //Create InfoWindow
       const infowindow = new window.google.maps.InfoWindow();
       //Set Dynamic Markers
       this.state.venues.map(newVenue => {

        //create marker
         const marker = new window.google.maps.Marker({
           position: {lat: newVenue.venue.location.lat, lng: 
           newVenue.venue.location.lng},
           map: map,
           id: newVenue.id,
           name: newVenue.venue.name,
           animation: window.google.maps.Animation.DROP
         })

         //infoWindow on click event
         marker.addListener('click', () => {
           if (marker.getAnimation() !== null) { marker.setAnimation(null); }
           else { marker.setAnimation(window.google.maps.Animation.BOUNCE); }
           setTimeout(() => { marker.setAnimation(null) }, 2000)
         });
         window.google.maps.event.addListener(marker, 'click', () => {
           infowindow.setContent(marker.name);
           infowindow.open(map, marker);
           map.setCenter(marker.position);

         });
         this.state.markers.push(marker);
         this.setState({ showedVenues : this.state.venues })
     });
}

    listEntryClick = (venue) => {
      let marker = this.state.markers.filter(m => m.id === venue.id)[0];
      this.infowindow.setContent(marker.name)
      this.infowindow.open(this.map, marker);

    }

0 个答案:

没有答案