如何覆盖 Google Map Api v3 中标记单击时的默认 panTo 行为?
默认情况下,当您单击标记时,地图会平移到该位置。
当我单击标记时,我希望地图以不同位置为中心(我计算出的附近点)。
问题是,地图移动到所需位置后,它会再次移动到单击的标记的中心。
我想覆盖此行为,我希望地图平移到所需位置并停留在那里,忽略单击了标记。
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经使用了这个,同时仍然通过制造商点击侦听器创建自定义信息窗口,所以这可能会有所帮助。
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