Google Maps V3 -> Is it possible to trigger the on click event on a specific coordinate (lat, lng) programmatically

牧云@^-^@ 提交于 2021-01-28 01:48:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!