clustering_google_maps 0.0.4+2

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 83

Clustering for Flutter Google Maps #

pub package

A Flutter package that recreate clustering technique in a Google Maps widget.

Developers Preview Status #

The package recreate the CLUSTERING technique in a Google Maps. It's work with data recordered in a dababase SQLite. I use sqflite (DB TECHNIQUE) It's work with a list of LatLngAndGeohash object. (MEMORY TECHNIQUE)

Usage #

To use this package, add clustering_google_maps as a dependency in your pubspec.yaml file.

For a better performance, at every zoom variation on the map, the package performs a specific query on the SQLite database, but you can force update with updateMap() method.

Getting Started #

DB TECHNIQUE #

To work properly, you must have the data of the points saved in a SQLite database. Latitude, longitude and the string of geohash. These three parameters are necessary for correct operation. If you have not saved the GEOHASH, I suggest you install GEOHASH plugin and save the value of Geohash in the points table of db.

For this solution you must use the db constructor of ClusteringHelper:

ClusteringHelper.forDB(...);

MEMORY TECHNIQUE #

To work properly you must have a list of LatLngAndGeohash object. LatLngAndGeohash is a simple object with Location and Geohash property, the last is generated automatically; you need only location of the point.

For this solution you must use the MEMORY constructor of ClusteringHelper:

ClusteringHelper.forMemory(...);

Future Implementations #

  • To further improve performance I am creating a way to perform sql queries only on the latlng bounding box displayed on the map.
  • I will insert custom marker with number of points. But for now Google Maps widget does not allow custom widget from dart but only static Bitmap

Quick Example for both solution #

import 'package:example/app_db.dart';
import 'package:example/fake_point.dart';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:clustering_google_maps/clustering_google_maps.dart';

class HomeScreen extends StatefulWidget {
  final List<LatLngAndGeohash> list;

  HomeScreen({Key key, this.list}) : super(key: key);

  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  ClusteringHelper clusteringHelper;
  final CameraPosition initialCameraPosition =
      CameraPosition(target: LatLng(0.000000, 0.000000), zoom: 0.0);

  Set<Marker> markers = Set();

  void _onMapCreated(GoogleMapController mapController) async {
    print("onMapCreated");
    if (widget.list == null) {
      clusteringHelper.database = await AppDatabase.get().getDb();
    }
    clusteringHelper.updateMap();
  }

  updateMarkers(Set<Marker> markers) {
    setState(() {
      this.markers = markers;
    });
  }

  @override
  void initState() {
    if (widget.list != null) {
      initMemoryClustering();
    } else {
      initDatabaseClustering();
    }

    super.initState();
  }

  // For db solution
  initDatabaseClustering() {
    clusteringHelper = ClusteringHelper.forDB(
      dbGeohashColumn: FakePoint.dbGeohash,
      dbLatColumn: FakePoint.dbLat,
      dbLongColumn: FakePoint.dbLong,
      dbTable: FakePoint.tblFakePoints,
      updateMarkers: updateMarkers,
    );
  }

  // For memory solution
  initMemoryClustering() {
    clusteringHelper = ClusteringHelper.forMemory(
      list: widget.list,
      updateMarkers: updateMarkers,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Clustering Example"),
      ),
      body: GoogleMap(
        onMapCreated: _onMapCreated,
        initialCameraPosition: initialCameraPosition,
        markers: markers,
        onCameraMove: (newPosition) => clusteringHelper.onCameraMove(newPosition, forceUpdate: false),
        onCameraIdle: clusteringHelper.onMapIdle,
      ),
      floatingActionButton: FloatingActionButton(
        child:
            widget.list == null ? Icon(Icons.content_cut) : Icon(Icons.update),
        onPressed: () {
          if (widget.list == null) {
            clusteringHelper.whereClause = "WHERE ${FakePoint.dbLat} > 42.6";
            clusteringHelper.updateMap();
          } else {
            clusteringHelper.updateMap();
          }
        },
      ),
    );
  }
}

See the example directory for a complete sample app.

0.0.4+2 #

  • Add secure MarkerId to marker

0.0.4+1 #

  • Add memory clustering fuction, now you can use clustering with a list of LatLngAndGeohash object
  • Add memory clustering to example
  • Now you can update the map during the user move or zoom the map (NOT RECOMMENDED)
  • Update Readme

0.0.4 #

  • Migrate to google_maps_flutter: 0.4.0
  • Remove rangeZoomUpdate properties (now the map will update with onMoveIdle callback)

0.0.3 #

  • Add optional WHERE clause for SQL query

0.0.2 #

  • Migrate to google_maps_flutter: 0.3.0+2

0.0.1+2 #

  • Add new marker for new level of aggregation.
  • Fix level for aggregation/disgregation
  • Add InfoWindowText on aggregated marker with number of points

0.0.1 #

  • Initial developers preview release.

example/README.md

example #

A new Flutter application.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  clustering_google_maps: ^0.0.4+2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:clustering_google_maps/clustering_google_maps.dart';
  
Version Uploaded Documentation Archive
0.0.4+2 Apr 14, 2019 Go to the documentation of clustering_google_maps 0.0.4+2 Download clustering_google_maps 0.0.4+2 archive
0.0.4+1 Apr 13, 2019 Go to the documentation of clustering_google_maps 0.0.4+1 Download clustering_google_maps 0.0.4+1 archive
0.0.4 Mar 29, 2019 Go to the documentation of clustering_google_maps 0.0.4 Download clustering_google_maps 0.0.4 archive
0.0.3 Mar 6, 2019 Go to the documentation of clustering_google_maps 0.0.3 Download clustering_google_maps 0.0.3 archive
0.0.2 Mar 4, 2019 Go to the documentation of clustering_google_maps 0.0.2 Download clustering_google_maps 0.0.2 archive
0.0.1+2 Feb 11, 2019 Go to the documentation of clustering_google_maps 0.0.1+2 Download clustering_google_maps 0.0.1+2 archive
0.0.1+1 Feb 10, 2019 Go to the documentation of clustering_google_maps 0.0.1+1 Download clustering_google_maps 0.0.1+1 archive
0.0.1 Feb 10, 2019 Go to the documentation of clustering_google_maps 0.0.1 Download clustering_google_maps 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
71
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
83
Learn more about scoring.

We analyzed this package on Apr 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14
  • Flutter: 1.4.7

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-1 points)

39 out of 39 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
geohash ^0.2.1 0.2.1
google_maps_flutter 0.4.0 0.4.0 0.5.7
path_provider ^0.4.1 0.4.1 0.5.0+1
sqflite ^0.12.2+1 0.12.2+1 1.1.5
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
path 1.6.2
sky_engine 0.0.99
synchronized 2.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test