• Stars
    star
    255
  • Rank 159,729 (Top 4 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 11 years ago
  • Updated about 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A clustering library for the Google Maps Android API v2

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.

More Repositories

1

JazzyListView

Java
935
star
2

TWTSideMenuViewController

Side Menus for iOS 7
Objective-C
851
star
3

TTSwitch

Fully customizable switch for iOS using images
Objective-C
432
star
4

SectionCursorAdapter

Java
110
star
5

multi-column-list-adapter

Java
100
star
6

TTAlertView

Objective-C
82
star
7

watchface-template

Java
79
star
8

Toast

Tools and Utilities for Cocoa Development
Objective-C
67
star
9

RecyclerViewLib

An example implementation of Android's new RecyclerView.
Java
63
star
10

HorizontalImageScroller-Android

A horizontal image scroller widget for Android
Java
50
star
11

MaterialRangeSlider

Material inspired range slider
Java
42
star
12

Wear-MessageApiDemo

Java
36
star
13

zbar

git clone of zbar sdk
Objective-C
35
star
14

AnimatedPath

Objective-C
33
star
15

AndroidStyleGuidelines

31
star
16

AndrOAuth

Java
29
star
17

hoot

A powerful, flexible, lightweight Android library for dealing with RESTful endpoints.
Java
26
star
18

watchface-gears

Java
20
star
19

UISpec

Git SVN Clone of UISpec
Objective-C
19
star
20

UISpecRunner

Flexible CLI test runner for UISpec
Ruby
16
star
21

FramerateDemo

Objective-C
11
star
22

toastdroid

Java
9
star
23

HelloAndroidStudio

Java
8
star
24

objective_stack

A Rails template used by the fine folks at Two Toasters
Ruby
7
star
25

TWTCommon

Misc. downright useful classes & additions for iphone development (with three 20)
Objective-C
7
star
26

project-example

Example repository demonstrating the twotoasters development process
6
star
27

Android-Master-Class-ListenerAwareAsyncTask

Java
6
star
28

fbconnect-iphone

Facebook Connect for iPhone
Objective-C
5
star
29

AnalyticsTest

Java
5
star
30

chron

Java
2
star
31

resource_controller_extensions

Provides reasonable default handlers for XML, JSON, and FBML to ResourceController
Ruby
2
star
32

iPhone-Build-Scripts

client build and release build scripts for iphone projects
Ruby
1
star
33

facebook-ios-sdk-framework

*Unofficial* build of the Facebook iOS SDK Framework
Objective-C
1
star
34

RKCatalog-Server

Simple Sinatra backend for the RestKit RKCatalog Sample app
Ruby
1
star
35

brominet

Objective-C
1
star
36

Xcode-Templates

Objective-C
1
star
37

Volley

Java
1
star