我正在开发在谷歌地图上使用标记的应用程序。然后我使用聚类来收集太近的标记。这是我的代码的一部分:
MapViewer.java
public class MapViewer extends Activity implements OnInfoWindowClickListener {
private GoogleMap map;
private ClusterManager<MyItem> mClusterManager;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapviewer);
try {
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
if (map != null) {
map.setMyLocationEnabled(true);
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
map.getUiSettings().setRotateGesturesEnabled(false);
mClusterManager = new ClusterManager<MyItem>(this, map);
mClusterManager.setRenderer(new MyClusterRenderer(this, map, mClusterManager));
map.setOnCameraChangeListener(mClusterManager);
map.setOnMarkerClickListener(mClusterManager);
map.setInfoWindowAdapter(new ClusterInfoWindow(getLayoutInflater()));
map.setOnInfoWindowClickListener(this);
addItems();
}
} catch (NullPointerException e) {
e.printStackTrace();
}
}
@Override
public void onInfoWindowClick(Marker marker) {
// My code
}
public void addItems() {
// My code
}
}
ClusterInfoWindow.java
public class ClusterInfoWindow implements InfoWindowAdapter {
LayoutInflater inflater = null;
public ClusterInfoWindow(LayoutInflater inflater) {
this.inflater = inflater;
}
@Override
public View getInfoWindow(Marker marker) {
return(null);
}
@Override
public View getInfoContents(Marker marker) {
View popup = inflater.inflate(R.layout.infowindow, null);
TextView tv = (TextView)popup.findViewById(R.id.title);
tv.setText(marker.getTitle());
tv = (TextView)popup.findViewById(R.id.snippet);
tv.setText(marker.getSnippet());
return(popup);
}
}
如果我点击单个标记,它会显示一个包含一些细节的弹出窗口。如果我点击一个群集,也会发生同样的情况。如何使群集无法点击?当用户点击群集时,我不想显示任何内容。 谢谢。
答案 0 :(得分:0)
基于Google地图的文档:
If you want to add specific functionality in response to a marker click event, set the map's OnMarkerClickListener() to the ClusterManager, since ClusterManager implements the listener.
因此,您可以将其更改为以下内容,而不是map.setOnMarkerClickListener(mClusterManager);
:
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
marker.showInfoWindow();
return false;
}
});
答案 1 :(得分:0)
您想要实现ClusterManager.OnClusterItemClickListener或ClusterManager.OnClusterItemInfoWindowClickListener