问题
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
回答1:
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/
来源:https://stackoverflow.com/questions/47973339/google-maps-v3-is-it-possible-to-trigger-the-on-click-event-on-a-specific-coo