简体   繁体   English

触摸标记时的Android应用程序地图中心

[英]Android App Map center when touchs a marker

When I touch a marker on map fragment (v.2), the map is centralized on the touched marker position. 当我触摸地图片段(v.2)上的标记时,地图会集中在触摸的标记位置上。 How can I drop this behavior? 我怎么能放弃这种行为? Is it possible? 可能吗? I'd like to keep the title being presented, but with no centralization. 我想保持标题的呈现,但没有集中化。

Thanks a lot, 非常感谢,

Julio 胡里奥

From the documentation : 文档

You can use an OnMarkerClickListener to listen for click events on the marker. 您可以使用OnMarkerClickListener侦听标记上的单击事件。 To set this listener on the map, call GoogleMap.setOnMarkerClickListener(OnMarkerClickListener). 要在地图上设置此侦听器,请调用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. 当用户单击标记时,将调用onMarkerClick(Marker)并将标记作为参数传递。 This method returns a boolean that indicates whether you have consumed the event (ie, you want to suppress the default behavior). 此方法返回一个布尔值,指示您是否已使用该事件(即,您要禁止默认行为)。 If it returns false, then the default behavior will occur in addition to your custom behavior. 如果返回false,则除了自定义行为外,还会发生默认行为。 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. 标记单击事件的默认行为是显示其信息窗口(如果可用)并移动摄像机,使标记在地图上居中。

This way, you can override the default behavior (center mark+show infowindow) with your custom behavior (show infowindow). 这样,您可以使用自定义行为(show infowindow)覆盖默认行为(中心标记+显示信息窗口)。 Something like this should work: 这样的事情应该有效:

On your OnMarkerClickListener : OnMarkerClickListener

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM