在infowindow谷歌地图内的Ionic 2点击事件

时间:2017-10-14 05:05:50

标签: javascript html google-maps ionic2 infowindow

您好我正试图从谷歌地图infowindow内的按钮发起一个事件。 问题是我无论如何都无法解雇它。

addMarket(latitud, longitud, sensorData) {

let marker = new google.maps.Marker({
  draggable: false,
  position: { lat: latitud, lng: longitud },
  map: this.map,//set map created here
  title: sensorData.sensor
});
marker.addListener('click', function () {
  infowindow.open(this.map, marker);
});

let bodyMessege = 'Nombre del Sensor: ' + sensorData.sensor + '<br>' +
  'Componente Descripcion: ' + sensorData.componentDesc + '<br>' +
  ' description:  ' + sensorData.description + '<br>' +
  ' Tipo de sensor: ' + sensorData.type + '<br>' +
  ' Unidad de sensor: ' + sensorData.unit + '<br>' +
  'Tipo de dato: ' + sensorData.dataType + '<br>' +
  '  <button ion-button (click)="this.navCtrl.push(DetalleSensorPage)" >Default</button>';

//      ' <button ion-button=""  onclick=console.log("log");'  anda
//this.pushPage=DetalleSensorPage;
var infowindow = new google.maps.InfoWindow({
  content: bodyMessege
});

欢迎任何提示,谢谢。 :)

1 个答案:

答案 0 :(得分:4)

我为自己的项目找到了这个解决方案:(https://forum.ionicframework.com/t/ng-click-in-google-maps-infowindow/5537/6

关键元素是你在下面的getElementbyId中寻找的id =“tap”。

let content = '<div class="infowindow"><p id="tap">your text here</p></div>';

let infoWindow = new google.maps.InfoWindow(
  {
    closeBoxURL: "",
    content: content
  }
);
infoWindow.open(this.map, marker);

google.maps.event.addListenerOnce(infoWindow, 'domready', () => {
  document.getElementById('tap').addEventListener('click', () => {
    //alert('Clicked');
    console.log("touch");
    this.closeInfoViewWindow(infoWindow);
    this.openEventDetailModal(event);
  });
});

希望这会对你和其他人有所帮助。