Clustering on Google Map V2 Part-2
We have gone through Clustering on Google map V2 in Clustering on Google Map V2 Part-1 .To overcome drawback of it , I searched for few days and i found one more library which independent from google play service library.
Screenshots :
Features :
- Clustering based on pixel proximity, not grid membership
- Animated cluster transitions
- Supports Android v2.2 (Froyo) and higher
Getting started :
- It's easy to add Clusterkraf to your app. Add the Clusterkraf library folder as an Android project to your Eclipse/ADT workspace, and reference it from your app as a library project.
- Clusterkraf provides an
InputPoint
class which holds aLatLng
position and anObject
tag. You just need to construct anArrayList<InputPoint>
object based on your model objects.
public class YourActivity extends FragmentActivity { YourMapPointModel[] yourMapPointModels = new YourMapPointModel[] { new YourMapPointModel(new LatLng(0d, 1d) /* etc */ ) }; ArrayList
inputPoints; private void buildInputPoints() { this.inputPoints = new ArrayList (yourMapPointModels.length); for (YourMapPointModel model : this.yourMapPointModels) { this.inputPoints.add(new InputPoint(model.latLng, model)); } } } - When your
GoogleMap
is initialized and yourArrayList<InputPoint>
is built, you can then initialize Clusterkraf.// YourActivity Clusterkraf clusterkraf; private void initClusterkraf() { if (this.map != null && this.inputPoints != null && this.inputPoints.size() > 0) { com.twotoasters.clusterkraf.Options options = new com.twotoasters.clusterkraf.Options(); // customize the options before you construct a Clusterkraf instance this.clusterkraf = new Clusterkraf(this.map, this.options, this.inputPoints); } }
Advance Options :
- To set any type of interpolator in cluster animation :
options.setTransitionInterpolator(interpolator); /* Types : AccelerateDecelerateInterpolator, AccelerateInterpolator, AnticipateInterpolator, AnticipateOvershootInterpolator, BounceInterpolator, DecelerateInterpolator, LinearInterpolator, OvershootInterpolator */
- Clusterkraf calculates whether InputPoint objects should join a cluster based on their pixel proximity. If you want to offer your app on devices with different screen densities, you should identify a Device Independent Pixel measurement and convert it to pixels based on the device's screen density at runtime.
options.setPixelDistanceToJoinCluster(dipDistanceToJoinCluster);
- To set zoom to bound animation duration :
options.setZoomToBoundsAnimationDuration(zoomToBoundsAnimationDuration);
- To set showInfoWindow animation duration :
options.setShowInfoWindowAnimationDuration(showInfoWindowAnimationDuration);
- To set behavior of marker click :
options.setSinglePointClickBehavior(singlePointClickBehavior); /* select from two types SHOW_INFO_WINDOW, NO_OP. */
- To set behavior of cluster click :
options.setClusterClickBehavior(this.options.clusterClickBehavior); /* select from three types ZOOM_TO_BOUNDS, SHOW_INFO_WINDOW, NO_OP. */
- To set behavior of cluster info window click :
options.setClusterInfoWindowClickBehavior(this.options.clusterInfoWindowClickBehavior); /* select from three types ZOOM_TO_BOUNDS, HIDE_INFO_WINDOW, NO_OP. */
- To set padding from window sides after zooming :
options.setZoomToBoundsPadding(pixels); /* When zooming to the bounds of a marker's backing ClusterPoint, zoom until * all of the points are at least this far from the edge of the GoogleMap's * bounds */
- To set marker click listner :
options.setOnMarkerClickDownstreamListener(new OnMarkerClickDownstreamListener(new OnMarkerClickDownstreamListener() { @Override public boolean onMarkerClick(Marker marker, ClusterPoint clusterPoint) { // TODO Auto-generated method stub return false; } }));
- To get methods of starting and finishing clustering :
options.setProcessingListener(this); /* generate two methods */ @Override public void onClusteringStarted() { } @Override public void onClusteringFinished() { }
5 comments: