google-maps-clustering

Fast marker clustering library for Google Maps Android API.

Github星跟蹤圖

Google Maps Clustering for Android

Download Android Arsenal

A fast marker clustering library for Google Maps Android API.

Demo

Motivation

Why not use Google Maps Android API Utility Library? Because it's very slow for large amounts of markers, which causes skipping frames and ANRs (see Issue #29, Issue #82). But this library can easily handle thousands of markers (the video above demonstrates the sample application with 20 000 markers running on Nexus 5).

Installation

  1. Make sure you have JCenter in your repository list:
repositories {
    jcenter()
}
  1. Add a dependency to your build.gradle:
dependencies {
    compile 'net.sharewire:google-maps-clustering:0.1.3'
}

Integration

  1. Implement ClusterItem to represent a marker on the map. The cluster item returns the position of the marker and an optional title or snippet:

class SampleClusterItem implements ClusterItem {

    private final LatLng location;

    SampleClusterItem(@NonNull LatLng location) {
        this.location = location;
    }

    @Override
    public double getLatitude() {
        return location.latitude;
    }

    @Override
    public double getLongitude() {
        return location.longitude;
    }

    @Nullable
    @Override
    public String getTitle() {
        return null;
    }

    @Nullable
    @Override
    public String getSnippet() {
        return null;
    }
}
  1. Create an instance of ClusterManager and set it as a camera idle listener using GoogleMap.setOnCameraIdleListener(...):
ClusterManager<SampleClusterItem> clusterManager = new ClusterManager<>(context, googleMap);
googleMap.setOnCameraIdleListener(clusterManager);
  1. To add a callback that's invoked when a cluster or a cluster item is clicked, use ClusterManager.setCallbacks(...):
clusterManager.setCallbacks(new ClusterManager.Callbacks<SampleClusterItem>() {
            @Override
            public boolean onClusterClick(@NonNull Cluster<SampleClusterItem> cluster) {
                Log.d(TAG, "onClusterClick");
                return false;
            }

            @Override
            public boolean onClusterItemClick(@NonNull SampleClusterItem clusterItem) {
                Log.d(TAG, "onClusterItemClick");
                return false;
            }
        });
  1. To customize the icons create an instance of IconGenerator and set it using ClusterManager.setIconGenerator(...). You can also use the default implementation DefaultIconGenerator and customize the style of icons using DefaultIconGenerator.setIconStyle(...).

  2. Populate ClusterManager with items using ClusterManager.setItems(...):

List<SampleClusterItem> clusterItems = generateSampleClusterItems();
clusterManager.setItems(clusterItems);

主要指標

概覽
名稱與所有者sharewire/google-maps-clustering
主編程語言Java
編程語言Java (語言數: 1)
平台
許可證Apache License 2.0
所有者活动
創建於2017-11-12 19:58:11
推送於2020-07-07 05:04:24
最后一次提交2018-03-06 16:04:24
發布數1
最新版本名稱v0.1.3 (發布於 )
第一版名稱v0.1.3 (發布於 )
用户参与
星數293
關注者數14
派生數76
提交數41
已啟用問題?
問題數27
打開的問題數14
拉請求數1
打開的拉請求數3
關閉的拉請求數5
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?