GoogleMapのInfoWindowのクリックイベントを取得する方法
GoogleMapのマーカーをクリックしたときのウィンドウ(InfoWindow)内にボタンを配置した場合、 普通のボタンのように(click)=onClick()みたいにしてもコンポーネント内の要素ではなくなるためonClick()関数が呼ばれません。
そこでちょっと無理やりですが以下のように対策
addMarker(stations) { for (let i = 0; i < stations.length; i++) { console.log(stations[i]); const markerLatLng = new google.maps.LatLng(stations[i]['latitude'], stations[i]['longitude']); this.marker[i] = new google.maps.Marker({ position: markerLatLng, map: this.map }); this.windows[i] = new google.maps.InfoWindow({ // 吹き出しの追加 content: '<div style="width: 220px;"><p>' + '<p>駅名:' + stations[i]['stationname'] + '</p>' + '<button id="go-station">この駅の詳細</button>' }); // ※※※ここからがボタンイベント追加部分です※※※ this.windows[i].addListener('domready', () => { document.getElementById('go-station').addEventListener('click', () => { this.goStation(); }); }); this.markerEvent(i); } } goStation() { // ※※※ここにボタンクリック時のイベント※※※ console.log('go station'); }