我正在寻找一种方法来禁用我的地图片段在所选标记功能上的自动中心。我仍然希望显示标记InfoWindow,但不要将整个地图置于我选择的标记上。
答案 0 :(得分:53)
看看以下帖子:
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;
}
});
答案 1 :(得分:31)
简单方法:
示例:
map.setOnMarkerClickListener(
new OnMarkerClickListener() {
boolean doNotMoveCameraToCenterMarker = true;
public boolean onMarkerClick(Marker marker) {
//Do whatever you need to do here ....
return doNotMoveCameraToCenterMarker;
}
});
答案 2 :(得分:5)
非常简单:
使用以下代码实现setOnMarkerClickListener()。
@Override
public boolean onMarkerClick(Marker marker) {
marker.showInfoWindow(); // show info window
return true; // can't move map by this
}
答案 3 :(得分:1)
简单。将moveOnMarkerPress
属性添加到MapView
并将其设置为false。
<MapView
moveOnMarkerPress={false}
>