Reputation: 227
Ok, the case is I'm working in Ionic 3 (which works with Angular 4), and I'm using google maps. Everything is fine to this point, except because I can't set up a click event listener for the infoWindow
object.
I wanna execute some code when the user clicks in the infoWindow
. Already tried the following:
google.maps.event.addListener(infowindow, 'click', function(){
console.log("click");
this.openPlace(place.id);
});
Also tried putting in a div with an id, which I later use with getDocumentById()
, and then adding an event listener to that div. Didn't work either. Same trying to put an onclick
event in that div, and calling to an Angular function. Nothing works.
What can I do to fix this issue?
Thanks!
Upvotes: 0
Views: 374
Reputation: 6652
https://developers.google.com/maps/documentation/javascript/reference#InfoWindow
InfoWindow object does not broadcast a click event.
This example is from Google's documentation:
function initMap() {
var originalMapCenter = new google.maps.LatLng(-25.363882, 131.044922);
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: originalMapCenter
});
var infowindow = new google.maps.InfoWindow({
content: 'Change the zoom level',
position: originalMapCenter
});
infowindow.open(map);
map.addListener('zoom_changed', function() {
infowindow.setContent('Zoom: ' + map.getZoom());
});
}
Notice how they are not adding listeners directly to the InfoWindow, but to the map. I can't find a single working example of a click listener bound directly to an InfoWindow.
Upvotes: 1