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() { }
Hi!
ReplyDeleteI'm trying to implement the same behaviour as before integrating clusterkraf into my app, so when I click on a single marker, the old infoWindow shall be shown, but it allways displays a little bubble with the markerOptions.title in it. Any suggestions?
Hi!
ReplyDeleteI'm trying to implement the same behaviour as before integrating clusterkraf into my app, so when I click on a single marker, the old infoWindow shall be shown, but it allways displays a little bubble with the markerOptions.title in it. Any suggestions?
Hi. This is very useful to me. thanks for sharing this post and i have one question "I want to mark some points that comes inside the radius of 10 meters from the center point." is that possible using Clustering?
ReplyDeleteHow you show the points on the map? I have followed the instructions but my map is totally blank :(
ReplyDeleteNice copy paste! from https://github.com/twotoasters/clusterkraf
ReplyDelete