我正在寻找一种方法来禁用我的 map fragment 在选定标记功能上的自动居中。我仍然希望标记 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;
}
});
关于android - 如何禁用android map 标记点击自动中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15925319/