gpt4 book ai didi

google-maps-api-3 - 当用户点击 map 上的(商业)地点时如何获取点击事件

转载 作者:行者123 更新时间:2023-12-04 02:55:39 26 4
gpt4 key购买 nike

我知道如何在 map 上设置点击事件,并且在点击随机位置时效果很好。但是当我点击一个商业地点时,谷歌地图会显示包含商业信息的气球,但不会向我的 JavaScript 引发点击事件。

您可以在此地理编码演示 (http://rjshade.com/projects/gmaps-autocomplete/) 中看到这种情况。浏览 map 到某个城市并单击一个随机位置:地址显示在文本框中(万岁!)。现在找到一些营业地点并单击它: map 弹出气球,但没有向 JavaScript 发送单击事件来更新文本框。具有讽刺意味的是:气球中提供了所需的地址信息!

如何处理谷歌地图商业地点的点击事件?

截屏:
clicking the 'ZOO' place pops up the balloon, but does not give the address in the search box, because no click event was received

最佳答案

编者注:此答案适用于 3.23 版。自 2016 年发布 3.24 版本以来,您可以使用 clickableIcons map 选项。 See this answer .

基本上没有选项来处理对 POI 的点击。

当然,您可以通过样式简单地隐藏这些功能,但是当您想让它们在 map 上可见时,这里有一个解决方法(基于:click event listener on styled map icons and labels):

当您单击 POI 时,会打开一个信息窗口,您可以在此处访问。

覆盖 setPosition -InfoWindow 的方法-prototype 以便触发 map 上的点击。

//keep a reference to the original setPosition-function
var fx = google.maps.InfoWindow.prototype.setPosition;

//override the built-in setPosition-method
google.maps.InfoWindow.prototype.setPosition = function () {

//logAsInternal isn't documented, but as it seems
//it's only defined for InfoWindows opened on POI's
if (this.logAsInternal) {
google.maps.event.addListenerOnce(this, 'map_changed',function () {
var map = this.getMap();
//the infoWindow will be opened, usually after a click on a POI
if (map) {
//trigger the click
google.maps.event.trigger(map, 'click', {latLng: this.getPosition()});
}
});
}
//call the original setPosition-method
fx.apply(this, arguments);
};

演示: http://jsfiddle.net/doktormolle/aSz2r/

关于google-maps-api-3 - 当用户点击 map 上的(商业)地点时如何获取点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24234106/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com