触摸标记时的Android App map 中心

标签 android google-maps marker google-maps-android-api-2

当我触摸 map fragment (v.2) 上的标记时, map 集中在触摸的标记位置上。我怎样才能放弃这种行为?可能吗?我想保留标题,但不集中。

非常感谢,

胡里奥

最佳答案

来自documentation :

You can use an OnMarkerClickListener to listen for click events on the marker. To set this listener on the map, call GoogleMap.setOnMarkerClickListener(OnMarkerClickListener). When a user clicks on a marker, onMarkerClick(Marker) will be called and the marker will be passed through as an argument. This method returns a boolean that indicates whether you have consumed the event (i.e., you want to suppress the default behavior). If it returns false, then the default behavior will occur in addition to your custom behavior. The default behavior for a marker click event is to show its info window (if available) and move the camera such that the marker is centered on the map.

这样,您可以使用自定义行为(显示信息窗口)覆盖默认行为(中心标记+显示信息窗口)。 这样的事情应该有效:

在您的 OnMarkerClickListener 上:

public boolean onMarkerClick(Marker marker) {
    marker.showInfoWindow();
    return true;
}

关于触摸标记时的Android App map 中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15202928/

相关文章:

android - 值从滚动 ListView 中消失 - Android

android - 使用 Symfony2 和 FOSUserBundle 从移动设备创建/登录用户

google-maps - v3 Google Maps Geocoding API是否具有表示准确性的字段?

leaflet - 如何在 leafletjs map 上扩展标记?

java - marker.setIcon 抛出 java.lang.IllegalArgumentException : Unmanaged descriptor

android - 底部导航 View - 渐变图标色调

Android Studio 和大量的模块

android - google-play-services-maps:17.0.0即使使用默认项目Android Studio创建也不起作用

ios - 旋转到横向时,Google Maps SDK for iOS 问题

javascript - 在 javascript 中向图像添加标记?