A clustering library for the Google Maps Android API v2

Related tags

SDK clusterkraf
Overview

DEPRECATED

Don't use this. The Maps v3 SDK handles markers. That with a few other cool utilities make this library obsolete!

Clusterkraf

A clustering library for the Google Maps Android API v2.

If you're using the Polaris v2 library, check out our pleiades branch.

Features

  • Clustering based on pixel proximity, not grid membership
  • Animated cluster transitions
  • Supports Android v2.2 (Froyo) and higher

Setup

Gradle

If you are using Gradle just add the following to your build.gradle file:

dependencies {
    compile 'com.twotoasters.clusterkraf:library:1.0.+'
}

Maven

If you are using maven add the following to your pom file:

<dependency>
    <groupId>com.twotoasters.clusterkraf</groupId>
    <artifactId>library</artifactId>
    <version>1.0.2</version>
</dependency>

Eclipse

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. Also, we assume you have a data object that holds latitude and longitude coordinates of each point you want plotted on the map similar to this:

public class YourMapPointModel {
    public LatLng latLng;
    public YourMapPointModel(LatLng latLng) {
        this.latLng = latLng;
    }
    // encapsulation omitted for brevity
}

Clusterkraf provides an InputPoint class which holds a LatLng position and an Object tag. You just need to construct an ArrayList<InputPoint> object based on your model objects similar to this example. In this example, we provide the model as the Object tag for the InputPoint so that we can later pass them back to you in callbacks as the ClusterPoint object's pointsInCluster list; see MarkerOptionsChooser, OnInfoWindowClickDownstreamListener, and OnMarkerClickDownstreamListener.

public class YourActivity extends FragmentActivity {
    YourMapPointModel[] yourMapPointModels = new YourMapPointModel[] { new YourMapPointModel(new LatLng(0d, 1d) /* etc */ ) };
    ArrayList<InputPoint> inputPoints;
        
    private void buildInputPoints() {
        this.inputPoints = new ArrayList<InputPoint>(yourMapPointModels.length);
        for (YourMapPointModel model : this.yourMapPointModels) {
            this.inputPoints.add(new InputPoint(model.latLng, model));
        }
    }
}

When your GoogleMap is initialized and your ArrayList<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);
    	}
    }

You've added a really sweet clustered map to your Android app.

For a more detailed example, take a look at the included sample app's source code.

Sample App

The sample app demonstrates Activity lifecycle, custom marker icons, click handling, and Clusterkraf's options. You can build it from source, or install it from https://play.google.com/store/apps/details?id=com.twotoasters.clusterkraf.sample.

Building the Sample App

  1. In your local checkout of the Clusterkraf git repo, do git submodule init and git submodule update.
  2. Add sample/ as a new Android project from existing source.
  3. Add sample/libs/ViewPagerIndicator as a new Android project from existing source.
  4. Authorize com.twotoasters.clusterkraf.sample built with your key of choice to your Google Maps for Android v2 API account.
  5. Create a new Values file private_strings.xml in sample/res/values/ and create a string named maps_api_key with your Google Maps for Android v2 API key.

License

Copyright 2013 Two Toasters

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • Make markers filterable based on title/credential?

    Make markers filterable based on title/credential?

    Is there any ability to filter the markers currently being shown? I need to filter the markers that are shown/clustered, with the ability to also remove that filter and show every marker. Is that possible in the library? I tried to add a delete method to the library in order to remove markers from the clusters (to go in hand with the add method), but the clustering didn't seem to update at all.

    opened by jamesaspence 3
  • Add the camera position event to the listener

    Add the camera position event to the listener

    In my project, I need to listen to the onCameraChanged of the Google map to present an animation to the user. With this commit, I added this function to the ProcessingListener to be able to do it with the clusterkraf.

    opened by igorcferreira 2
  • Added an optional custom InfoWindowAdapter

    Added an optional custom InfoWindowAdapter

    Added an optional custom InfoWindowAdapter that passes the ClusterPoint to its methods.

    I needed to use an InfoWindowAdapter for the balloons, but the official Adapter only gives the Marker as parameter, and because of my layer architecture I couldn't do much with it. So I decided to use the same pattern that you use for other listeners, and it works like a charm.

    I tried to mirror your code style and comments in case you want to merge this feature. Awesome library, by the way ;)

    opened by Sloy 2
  • ConcurrentModificationException in ClustersBuilder.addAll()

    ConcurrentModificationException in ClustersBuilder.addAll()

    java.lang.RuntimeException: An error occured while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:299) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352) at java.util.concurrent.FutureTask.setException(FutureTask.java:219) at java.util.concurrent.FutureTask.run(FutureTask.java:239) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) at java.lang.Thread.run(Thread.java:856) Caused by: java.util.ConcurrentModificationException at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:569) at com.twotoasters.clusterkraf.ClustersBuilder.addAll(ClustersBuilder.java:54) at com.twotoasters.clusterkraf.ClusteringTask.doInBackground(ClusteringTask.java:34) at com.twotoasters.clusterkraf.ClusteringTask.doInBackground(ClusteringTask.java:1) at android.os.AsyncTask$2.call(AsyncTask.java:287) at java.util.concurrent.FutureTask.run(FutureTask.java:234) ... 3 more

    bug library 
    opened by carltonwhitehead 2
  • NullPointerException in sample app ToastedMarkerOptionsChooser on certain devices

    NullPointerException in sample app ToastedMarkerOptionsChooser on certain devices

    java.lang.NullPointerException at android.graphics.Bitmap.copy(Bitmap.java:400) at com.twotoasters.clusterkraf.sample.ToastedMarkerOptionsChooser.getClusterBitmap(ToastedMarkerOptionsChooser.java:95) at com.twotoasters.clusterkraf.sample.ToastedMarkerOptionsChooser.choose(ToastedMarkerOptionsChooser.java:67) at com.twotoasters.clusterkraf.ClusterTransitionsAnimation.addMarker(ClusterTransitionsAnimation.java:243) at com.twotoasters.clusterkraf.ClusterTransitionsAnimation.onAnimationStart(ClusterTransitionsAnimation.java:201) at com.nineoldandroids.animation.ValueAnimator.start(ValueAnimator.java:937) at com.nineoldandroids.animation.ValueAnimator.start(ValueAnimator.java:951) at com.nineoldandroids.animation.ObjectAnimator.start(ObjectAnimator.java:385) at com.twotoasters.clusterkraf.ClusterTransitionsAnimation.animate(ClusterTransitionsAnimation.java:52) at com.twotoasters.clusterkraf.Clusterkraf.transitionClusters(Clusterkraf.java:175) at com.twotoasters.clusterkraf.Clusterkraf.access$16(Clusterkraf.java:173) at com.twotoasters.clusterkraf.Clusterkraf$ClusterTransitionsBuildingTaskHost.onClusterTransitionsBuildingTaskPostExecute(Clusterkraf.java:506) at com.twotoasters.clusterkraf.ClusterTransitionsBuildingTask.onPostExecute(ClusterTransitionsBuildingTask.java:53) at com.twotoasters.clusterkraf.ClusterTransitionsBuildingTask.onPostExecute(ClusterTransitionsBuildingTask.java:1) at android.os.AsyncTask.finish(AsyncTask.java:417) at android.os.AsyncTask.access$300(AsyncTask.java:127) at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:143) at android.app.ActivityThread.main(ActivityThread.java:4914) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:521) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) at dalvik.system.NativeStart.main(Native Method)

    bug sample 
    opened by carltonwhitehead 2
  • Adding to maven central

    Adding to maven central

    Added the ability to upload to maven central Uploaded and released on mavencentral Updated the read me for gradle and maven Updated ViewPagerIndicator and changed the url (insecure type) Updated gradle to work with the android studio 0.5+.

    opened by MinceMan 1
  • problem of showing clustered icon instead of a single marker icon

    problem of showing clustered icon instead of a single marker icon

    Hi, I just tried to add this library to my project which has more than two thousands markers and it works good except that when I zoom to see my single markers outside of the clusters, it shows the single marker but it seem that it still is inside the cluster and shows the clustered icon and also '2' number on the icon which indicates it has 2 markers but I'm sure it is just one marker. Do you have any clue why this may happen ?

    Thanks in advance

    opened by ngooran 0
  • Loading spinner sometimes stays on when returning to SampleActivity from TwoToastersActivity

    Loading spinner sometimes stays on when returning to SampleActivity from TwoToastersActivity

    Steps to reproduce

    1. Start sample app in Normal Mode
    2. Zoom until Two Toasters office is drawn as a single marker
    3. Tap the Two Toasters office marker to open the TwoToastersActivity
    4. Navigate back to SampleActivity (hardware back button or ActionBar up)
    5. If loading spinner is not already spinning indefinitely, repeat steps 3 and 4 (sometimes it doesn't happen on the first try, but will on the second as long as the camera position doesn't change)

    Expected results

    Either no loading spinner is shown at all, or the loading spinner is only visible very briefly (substantially less than one second)

    Actual results

    The loading spinner is shown forever, or until the camera position is changed

    bug library sample 
    opened by carltonwhitehead 0
  • Unsupported as v3 supports clustering is not true

    Unsupported as v3 supports clustering is not true

    Readme says not to use and is no longer supported as v3 has clustering support. This is not true, there is no V3 for Android.

    Also worth mentioning that google does have a utility lib to support clustering, it is however crazy slow.

    opened by newmanw 0
  • Library is having application icon and theme

    Library is having application icon and theme

    As the main application will already have application icon and theme in place. While building the app fails with following

    Error:(39, 9) Attribute application@icon value=(@drawable/launcher_icon) from AndroidManifest.xml:39:9 Error:(41, 9) Attribute application@theme value=(@style/Theme.rctheme) from AndroidManifest.xml:41:9 is also present at com.twotoasters.clusterkraf:library:1.0.2:5:115 value=(@style/AppTheme) Suggestion: add 'tools:replace="android:theme"' to element at AndroidManifest.xml:37:5 to override Error:Execution failed for task ':handset:processDebugManifest'.

    Manifest merger failed with multiple errors, see logs

    Possible Resolution replace the manifest

    current one

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
    </application>
    

    new one

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    
    opened by Raghuramchowdary-tech 5
  • Possibility of multiple Clusterized Icons

    Possibility of multiple Clusterized Icons

    Hi, My question is about the possibility of multiple icons in clusters, based on data. Example: I have POI -s on map, base on it's types it can have different types of icons. But I couldn't find out how to do that in ClusterKraf. As I know we can customise the icon in overrided "choose" function in extended MarkerOptionsChooser. But there I do not have which POI is under customisation. InputPoints can be only reached by index, cannot get the container array list itself, so if i iterate it with index (getInputPointAtOffset(index)) it can easily overrun. I have no other idea how to get current InputPoint, which can hold the type of the input point. Thanks, peter

    opened by peterszucs 1
  • Cursor and show tooltip default

    Cursor and show tooltip default

    Hello

    I use this library and it is really great. I have not found a way to initialize default cursors to display a tooltip with showInfoWindow() method Is there the possibility to do so?

    Thank you in advance,

    opened by thomasl76 0
Owner
Ticketmaster Mobile Studio
Formerly Two Toasters
Ticketmaster Mobile Studio
Small library that wraps Google Play Service API in brilliant RxJava Observables reducing boilerplate to minimum.

ReactiveLocation library for Android Small library that wraps Google Play Services API in brilliant RxJava Observables reducing boilerplate to minimum

Michał Charmas 2.1k Dec 4, 2022
Donations library for Android. Supports Google Play Store, Flattr, PayPal, and Bitcoin

Android Donations Lib Android Donations Lib supports donations by Google Play Store, Flattr, PayPal, and Bitcoin. It is used in projects, such as Open

Sufficiently Secure 346 Jan 8, 2023
Donations library for Android. Supports Google Play Store, Flattr, PayPal, and Bitcoin

Android Donations Lib Android Donations Lib supports donations by Google Play Store, Flattr, PayPal, and Bitcoin. It is used in projects, such as Open

Sufficiently Secure 345 Dec 21, 2022
Its measurement app made using kotlin with sceneform sdk by google

ARCORE MEASUREMENT This app is build using sceneform sdk for android using kotlin language It helps you measure the distance between multiple points i

Kashif Mehmood 39 Dec 9, 2022
Horoscope API for android to get the horoscope according to the sunsign

Horoscope-API. Simple Java API to get the horoscope according to the sunsign. Contents Features Implementation API Usage To-dos Credits License Featur

TheBotBox 34 Dec 2, 2022
realworld api 프로젝트입니다.

Real world author: chance0523 origin project : https://github.com/gothinkster/realworld/tree/master/api This application uses... Kotlin Spring Boot JP

서정준 4 Jul 19, 2021
CodingChallenge: A simple SDK. Which can provide you information related to Start Wars APi

CodingChallenge CodingChallenge is a simple SDK. Which can provide you informati

Wajahat Hussain 1 Feb 18, 2022
HubSpot Kotlin SDK 🧺 Implementation of HubSpot API for Java/Kotlin in tiny SDK

HubSpot Kotlin SDK ?? Implementation of HubSpot API for Java/Kotlin in tiny SDK

BOOM 3 Oct 27, 2022
Android Weather Library: android weather lib to develop weather based app fast and easily

WeatherLib Android weather lib is an android weather aggregator. The lib helps you getting weather data from the most importat weather provider. It su

Surviving with android (by Francesco Azzola) 641 Dec 23, 2022
Library for Android In-App Billing (Version 3+)

Checkout (Android In-App Billing Library) Description Checkout is an implementation of Android In-App Billing API (v3+). Its main goal is to make inte

Sergey Solovyev 1k Nov 26, 2022
Android library project for providing multiple image selection from the device.

PolyPicker Android library project for selecting/capturing multiple images from the device. Result Caution! Eclipse library project structure has been

JW 407 Dec 27, 2022
Android library that provides for multiple image selection.

#MultipleImageSelect An android library that allows selection of multiple images from gallery. It shows an initial album (buckets) chooser and then im

Darshan Dorai 299 Nov 14, 2022
this is the demo of billing new library v3

Billing library v3 demo android This is the demo of billing new library v3 for android native IMPORTANT 1- you must have login to google play store to

Muhammad Sikandar 3 Dec 6, 2021
Sdk-android - SnapOdds Android SDK

Documentation For the full API documentation go to https://snapodds.github.io/sd

Snapodds 0 Jan 30, 2022
AWS SDK for Android. For more information, see our web site:

AWS SDK for Android For new projects, we recommend interacting with AWS using the Amplify Framework. The AWS SDK for Android is a collection of low-le

AWS Amplify 976 Dec 29, 2022
Accept PayPal and credit cards in your Android app

Important: PayPal Mobile SDKs are Deprecated. The APIs powering them will remain operational long enough for merchants to migrate, but the SDKs themse

PayPal 802 Dec 22, 2022
Powerful custom Android Camera with granular control over the video quality and filesize, restricting recordings to landscape only.

LandscapeVideoCamera Highly flexible Android Camera which offers granular control over the video quality and filesize, while restricting recordings to

Jeroen Mols 1.2k Dec 29, 2022
Countly Product Analytics Android SDK

Countly Android SDK We're hiring: Countly is looking for Android SDK developers, full stack devs, devops and growth hackers (remote work). Click this

Countly Team 648 Dec 23, 2022
Android Real Time Chat & Messaging SDK

Android Chat SDK Overview Applozic brings real-time engagement with chat, video, and voice to your web, mobile, and conversational apps. We power emer

Applozic 659 May 14, 2022