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

最佳答案

看一下以下帖子:

Don't snap to marker after click in 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;
}
});

10-07 19:40
查看更多