如何覆盖 Google Map Api v3 中标记单击时的默认 panTo 行为?

发布于 2025-01-07 16:53:26 字数 324 浏览 0 评论 0原文

默认情况下,当您单击标记时,地图会平移到该位置。

当我单击标记时,我希望地图以不同位置为中心(我计算出的附近点)。

问题是,地图移动到所需位置后,它会再次移动到单击的标记的中心。

我想覆盖此行为,我希望地图平移到所需位置并停留在那里,忽略单击了标记。

google.maps.event.addListener(marker, 'click', function() {
    map.panTo(differentLatLng);
});

我尝试向事件处理程序添加“return false”,但默认处理仍然存在。

By default when you click on a marker the map pans to that location.

When I click on a marker, I want the map to center on a different location (a nearby point I have calculated).

The problem is that after the map moves to the desired location, it moves again to center on the clicked marker.

I want to override this behaviour, I want the map pan to the desired location and stay there ignoring that the marker was clicked.

google.maps.event.addListener(marker, 'click', function() {
    map.panTo(differentLatLng);
});

I tried adding a "return false" to the event handler, but the default handling persists.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剩一世无双 2025-01-14 16:53:26

我已经使用了这个,同时仍然通过制造商点击侦听器创建自定义信息窗口,所以这可能会有所帮助。

infoWindow = new google.maps.InfoWindow({disableAutoPan: true});

埃里克

I've used this while still creating a custom infoWindow via maker click listener, so this might help.

infoWindow = new google.maps.InfoWindow({disableAutoPan: true});

Eric

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文