【问题标题】:Google Maps V3 -> Is it possible to trigger the on click event on a specific coordinate (lat, lng) programmaticallyGoogle Maps V3 -> 是否可以以编程方式触发特定坐标(lat,lng)上的点击事件
【发布时间】:2018-06-06 23:40:37
【问题描述】:

这个问题与我的问题有关:

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

由于可以像这样以编程方式触发点击事件,我想知道是否可以以相同的方式在给定的纬度/经度位置触发点击事件?

示例代码:

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

我想做的伪代码:

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

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

鉴于文档,这确实是一个很长的尝试,但它会解决我当前的问题。

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

【问题讨论】:

    标签: javascript google-maps google-maps-api-3


    【解决方案1】:

    您可以尝试将其他参数传递给trigger 方法:

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

    这是一个工作示例,显示每次单击地图时(或在编程触发器上)时的 infoWindow:https://jsfiddle.net/beaver71/5ndjq8ge/

    【讨论】:

    • 谢谢,我需要在点击时触发数据,但只需要稍作修改。代码示例:google.maps.event.trigger(this.map.data, 'click', { coord: place.geometry.location, number: 2 });
    猜你喜欢
    • 1970-01-01
    • 2021-06-04
    • 2011-03-30
    • 2011-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-12
    • 2013-02-04
    相关资源
    最近更新 更多