4

This question is related to my question here:

Google Maps V3 -> Is it possible to get properties from Geojson using lat lng coordinates or other information from search box?

Since it is possible to trigger a click event programmatically like this, I'm wondering if I can trigger a click event on a given lat/lng position in the same way?

Example code:

google.maps.event.trigger(marker, 'click');

Pseudo code of what I would like to do:

google.maps.event.trigger(place.geometry.location, 'click');

How to trigger the onclick event of a marker on a Google Maps V3?

Given the documentation it is really a long shot, but it would solve my current problem.

https://developers.google.com/maps/documentation/javascript/3.exp/reference#event

beaver
  • 17,333
  • 2
  • 40
  • 66
Ogglas
  • 62,132
  • 37
  • 328
  • 418

1 Answers1

7

You can try passing additional arguments to trigger method:

var e = {
  latLng: new google.maps.LatLng(-35, 151)
};
google.maps.event.trigger(map, 'click', e);

Here is a working example showing infoWindow every time map is clicked (or on programmatic trigger): https://jsfiddle.net/beaver71/5ndjq8ge/

beaver
  • 17,333
  • 2
  • 40
  • 66
  • Thanks, I needed to trigger the data on click but that only required a small modification. Code example for that: `google.maps.event.trigger(this.map.data, 'click', { coord: place.geometry.location, number: 2 });` – Ogglas Dec 26 '17 at 11:50