Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 2 click event inside infowindow googlemaps

Hi i'm trying to fire an event from a button inside a google maps infowindow. the problem is that i can´t make it fire by any mean.

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
});

Any tip will be welcome thanks. :)

like image 965
S.Regusci Avatar asked Mar 08 '23 20:03

S.Regusci


1 Answers

I have found this solution for my own project: ( https://forum.ionicframework.com/t/ng-click-in-google-maps-infowindow/5537/6)

The key element is the id="tap" that you look for at the getElementbyId below.

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);
  });
});

hope this will help you and others.

like image 179
Raphaël Avatar answered Mar 10 '23 09:03

Raphaël