Javascript 信息窗口谷歌地图中的Ionic 2点击事件

Javascript 信息窗口谷歌地图中的Ionic 2点击事件,javascript,html,google-maps,ionic2,infowindow,Javascript,Html,Google Maps,Ionic2,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.s

嗨,我正试图从谷歌地图信息窗口内的按钮触发一个事件。 问题是我无论如何都不能让它着火

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
});
addMarket(纬度、经度、传感器数据){
让marker=new google.maps.marker({
可拖动:错误,
位置:{lat:latitud,lng:longitud},
map:this.map,//设置在此创建的映射
标题:sensorData.sensor
});
marker.addListener('click',函数(){
infowindow.open(this.map,marker);
});
让bodyMessege='Nombre del Sensor:'+sensorData.Sensor+'
'+ “组件描述:”+sensorData.componentDesc+”
'+ '说明:'+sensorData.description+'
'+ “Tipo de sensor:”+sensorData.type+“
”+ “Unidad de sensor:”+sensorData.unit+“
”+ “Tipo de dato:”+sensorData.dataType+“
”+ “违约”;
//“我为自己的项目找到了这个解决方案:()

关键元素是您在下面的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);
  });
});
let content='

您的文本在这里

; 让infoWindow=new google.maps.infoWindow( { closeBoxURL:“”, 内容:内容 } ); infoWindow.open(this.map,marker); google.maps.event.addListenerOnce(信息窗口,'domready',()=>{ document.getElementById('tap')。addEventListener('click',()=>{ //警报(“点击”); 控制台日志(“触摸”); 这个.closeInfoViewWindow(infoWindow); 此.openEventDetailModal(事件); }); });

希望这将对您和其他人有所帮助。

我能够解决这个问题,但我不确定这是否是相同的情况。在我这方面,要求一次只显示一个信息视图,并在其中包含一个按钮。因此,如果您首先打开一个信息视图,然后单击另一个标记,则第一个信息视图将关闭,只有新的信息视图将显示e显示。可以吗?这是相同的要求,每次只显示一个弹出窗口,当按下标记时,信息窗口显示信息,并有一个按钮重定向到另一个页面,显示更多详细信息。我尝试从按钮调用函数,但我连控制台日志都无法运行。如果有帮助,您可以使用类似的工具点击地图区域时打开信息窗口的地方。仅供参考,这也是一个Ionic 2应用程序。