我正在开发基于地图的应用程序,我使用集群来安排标记。它工作正常。现在,我需要在单击clusterManager时显示一条消息,当我单击item(只有一个标记)时,我可以在它们之间产生差异。
这是我的代码,setOnClusterClickListener
并且setOnClusterItemClickListener
没有调用,所以请问我的代码出了什么问题。
mClusterManager = new ClusterManager<MyItem>(this, getMap());
getMap().setOnCameraChangeListener(mClusterManager);
try {
readItems();
} catch (JSONException e) {
Toast.makeText(this, "Problem reading list of markers.", Toast.LENGTH_LONG).show();
}
mClusterManager.setOnClusterClickListener(new ClusterManager.OnClusterClickListener<MyItem>() {
@Override
public boolean onClusterClick(Cluster<MyItem> cluster) {
Log.d("cluster","clicked");
return true;
}
});
mClusterManager.setOnClusterItemClickListener(new ClusterManager.OnClusterItemClickListener<MyItem>() {
@Override
public boolean onClusterItemClick(MyItem item) {
Log.d("cluster item","clicked");
return true;
}
});
getMap().setOnMarkerClickListener(mClusterManager);
答案 0 :(得分:3)
你应该在setOnClusterClickListener和setOnClusterItemClickListener之前调用setOnMarkerClickListener
mClusterManager = new ClusterManager<MyItem>(this, getMap());
getMap().setOnMarkerClickListener(mClusterManager); //
getMap().setOnCameraChangeListener(mClusterManager);
try {
readItems();
} catch (JSONException e) {
Toast.makeText(this, "Problem reading list of markers.", Toast.LENGTH_LONG).show();
}
mClusterManager.setOnClusterClickListener(new ClusterManager.OnClusterClickListener<MyItem>() {
@Override
public boolean onClusterClick(Cluster<MyItem> cluster) {
Log.d("cluster","clicked");
return true;
}
});
mClusterManager.setOnClusterItemClickListener(new ClusterManager.OnClusterItemClickListener<MyItem>() {
@Override
public boolean onClusterItemClick(MyItem item) {
Log.d("cluster item","clicked");
return true;
}
});