36

我正在寻找一种方法来禁用我的地图片段在选定标记功能上的自动居中。我仍然希望标记 InfoWindow 显示出来,但只是不将整个地图集中在我选择的标记上。

4

4 回答 4

55

看看下面的帖子:

在android map v2中单击后不要捕捉到标记

@DMan提供了一个方法,基本上你需要使用OnMarkerClick事件并覆盖默认行为:

// Since we are consuming the event this is necessary to
// manage closing openned markers before openning new ones
Marker lastOpenned = null;

mMap.setOnMarkerClickListener(new OnMarkerClickListener() {
public boolean onMarkerClick(Marker marker) {
    // Check if there is an open info window
    if (lastOpenned != null) {
        // Close the info window
        lastOpenned.hideInfoWindow();

        // Is the marker the same marker that was already open
        if (lastOpenned.equals(marker)) {
            // Nullify the lastOpenned object
            lastOpenned = null;
            // Return so that the info window isn't openned again
            return true;
        } 
    }

    // Open the info window for the marker
    marker.showInfoWindow();
    // Re-assign the last openned such that we can close it later
    lastOpenned = marker;

    // Event was handled by our code do not launch default behaviour.
    return true;
}
});
于 2013-04-10T12:08:44.403 回答
35

简单的方法:

  1. 实现 setOnMarkerClickListener()
  2. 返回 '​​TRUE' 以防止 GoogleMap 默认将地图中心移动到标记处。

例子:

map.setOnMarkerClickListener(
    new OnMarkerClickListener() {
        boolean doNotMoveCameraToCenterMarker = true;
        public boolean onMarkerClick(Marker marker) {
            //Do whatever you need to do here ....
            return doNotMoveCameraToCenterMarker;
        }
    });
于 2013-05-29T18:48:46.807 回答
8

非常简单:

使用下面的代码来实现 setOnMarkerClickListener()。

@Override
public boolean onMarkerClick(Marker marker) {

    marker.showInfoWindow(); // show info window

    return true; // can't move map by this
} 
于 2017-06-30T08:53:34.590 回答
2

简单的。添加moveOnMarkerPress道具MapView并将其设置为false。

 <MapView
      moveOnMarkerPress={false}
>
于 2020-06-28T07:03:44.093 回答