I can't seem to trigger an event on a marker...in particular the 'markerClick' event. Anyway to do this like the javascript API?
marker.trigger(plugin.google.maps.event.MARKER_CLICK);
https://github.com/mapsplugin/cordova-plugin-googlemaps/wiki/BaseClass#trigger
Hello!
How can I do if I have only an array with "MarkerOptions" and a MarkerCluster?
I have not access to "Marker" objects, because I initialise the MarkerCluster with that array.
But i want to trigger the click event on one of the markers that i can see on the viewport.
(So there must be a Marker object)
Is there any way to get the "Marker" objects that are shown on the viewport?
So I can then trigger the MARKER_CLICK event.
(I am using Ionic Framework 3)
Thanks in advance :)
I'd also like to know how to trigger a click on a marker made with map.addMarkerCluster().
@guillerial Figured it out. Markers are created in order they are provided. They are assigned an id that looks like marker_0 - 0 being the index of the first marker you provde in array. So to trigger a click event. First get the marker with const marker = markerClusterer.getMarkerById('marker_0'); then instead of triggering a MARKER_CLICK on the marker, trigger it on the clusterer, like so markerClusterer.trigger(window.plugin.google.maps.event.MARKER_CLICK, latLng, marker);. And that should do it. In my case the info window for that marker still didn't open but that was because the event was too fast. I simply did window.setTimeout for that MARKER_CLICK event and info window showed up.
Good luck.
@cxminer Are you also using Ionic? It seems that the MarkerClusterer does not provide the getMarkerById method. Although the method seems to be implemented looking at the (VanillaJS) source files there are no TS typings for it. Hence we don't see any possibility to get the marker from the cluster.
@JZubero I found getMarkerById by dumping the MarkerClusterer object to console and analyzing its properties - it is not part of the documentation. but it is there and can be used.
Note that @ionic-native/google-maps does NOT expose getMarkerById. You can only find it by creating the MarkerClusterer directly _(look inside __proto__ - two levels down)_.
@wf9a5m75 would it be possible to add getMarkerById method to the @ionic-native/google-maps plugin to solve this?
nop. It's an internal function.
@wf9a5m75 So it's not possible to trigger a click on a marker made with map.addMarkerCluster() on Ionic?
@cxminer Wow, thank you for the approach!
It would be great to have an official way to do it.
That function is intended for internal use. Not for generic use, because marker is not always generated.
I will provide alternative way.
I will provide alternative way.
Is there another way to trigger the click event on a marker?