I will give you a nice workaround. First, I will give some background. Then, I will tell you the very simple method for modifying your code.
BACKGROUND: Let's first look at the implementation of ClusterManager.addItem from the library code:
public void addItem(T myItem) {
this.mAlgorithmLock.writeLock().lock();
try {
this.mAlgorithm.addItem(myItem);
} finally {
this.mAlgorithmLock.writeLock().unlock();
}
}
As you can see, when you call clusterManager.addItem, the ClusterManager then calls this.mAlgorithm.addItem. mAlgorithm is where your item is stored. Let's now look at the default constructor of ClusterManager:
public ClusterManager(Context context, GoogleMap map, MarkerManager markerManager) {
...
this.mAlgorithm = new PreCachingAlgorithmDecorator(new NonHierarchicalDistanceBasedAlgorithm());
...
}
mAlgorithm is instantiated as a PreCachingAlgorithmDecorator containing a NonHierarchicalDistanceBasedAlgorithm. Unfortunately, since mAlgorithm is declared private, we don't have access to the items which are being added to the algorithm. However, there is happily an easy workaround! We simply instantiate mAlgorithm using ClusterManager.setAlgorithm. This allows us access to the algorithm class.
WORKAROUND: Here is your code with the workaround inserted.
Put this declaration with your class variables:
private Algorithm<Post> clusterManagerAlgorithm;
In the place where you instantiate your ClusterManager, put this immediately afterwards:
// Instantiate the cluster manager algorithm as is done in the ClusterManager
clusterManagerAlgorithm = new NonHierarchicalDistanceBasedAlgorithm();
// Set this local algorithm in clusterManager
clusterManager.setAlgorithm(clusterManagerAlgorithm);
You can leave your code for inserting items into the cluster exactly the same.
When you want to get access to the items inserted, you simply use the algorithm as opposed to the ClusterManager:
Collection<ClusterItemImpl> items = clusterManagerAlgorithm.getItems();
This returns the items instead of the Marker objects, but I believe it is what you need.