Cluster markers, geocoordinates or anything that responds to latitude and longitude.

Why serverside clustering

Of cause there are lots of libs to cluster large amounts of markers in the frontend, but the expensive part is to transfer all those markers to the client. In my case it was the difference between sending 10_000 markers - or 20.


As part of the Gemfile or by hand, nothing unusual here.


Clumpy takes points, typically geocoordinates, and puts them together into clusters.

It requires the given points to be ruby objects, responding to #latitude and #longitude methods.

require 'ostruct'

Point =, :longitude)
points = [ 101, longitude: 11), 102, longitude: 12), 201, longitude: 21)

Now those points may be clustered easily:

builder  =
clusters = builder.cluster

cluster = clusters.first
cluster.size                 # => 2
cluster.latitude             # => 101.5
cluster.longitude            # => 11.5
cluster.points               # => points 1 and 2 from above
cluster.bounds               # => represents the area this cluster covers
cluster.to_json              # => well, json representation of that.

Optionally you could add a precision: :high option to the builder initialization to move the cluster a little bit after all points were assigned.


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request


WTFPL - What The Fuck You Want To Public License