如何禁用android地图标记点击自动中心

我正在寻找一种方法来禁用我select的标记function的地图片段的自动中心。 我仍然希望标记InfoWindow显示出来,但是不要将整个地图放在我select的标记上。

看看下面的post:

在Android地图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. 实现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; } }); 

很简单:

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

 @Override public boolean onMarkerClick(Marker marker) { marker.showInfoWindow(); // show info window return true; // can't move map by this }