6

I'm wondering if any of you knows a method (library, category, etc.) to cluster iOS MapAnnotations if there are many of them at the same location (e.g. 4 pieces in about 10m).

It doesn't matter to zoom in because they are still overlapping. I've already tried https://github.com/applidium/ADClusterMapView (and sombe other libs) but all of them are made for showing clusters in zoom-out-scenarios. None of them really respect the distance between annotations when zoomed in.

I'm working on an app with an offline-db so a server-side solution is not an option.

thank you for your help!

kimar
  • 191
  • 2
  • 8
  • 1
    Apple have provided the example for doing this thing: Please checkout apple's own example over here: https://developer.apple.com/library/ios/samplecode/PhotoMap/Introduction/Intro.html – Mehul Thakkar Feb 24 '16 at 09:30

3 Answers3

4

You don't need 3rd party framework's anymore. iOS 11 has native clustering support.

You need to implement mapView:clusterAnnotationForMemberAnnotations: method.

Get more details in the Apple example: https://developer.apple.com/sample-code/wwdc/2017/MapKit-Sample.zip

ricardopereira
  • 11,118
  • 5
  • 63
  • 81
  • I cannot find clusterAnnotationForMemberAnnotations method in zip above :( – djdance Nov 30 '18 at 07:20
  • @djdance Yes, you're right. The sample does not customize the cluster annotations. That method is for customisation but MapKit creates those annotation objects automatically. You can see from the example how the clustering works by looking at the `ViewController.swift`. – ricardopereira Nov 30 '18 at 14:38
  • Do you know how to manage that "automatic"? I want to change grid size – djdance Nov 30 '18 at 19:27
  • @djdance Grid size? Do you mean the tiles? Have a look at https://www.raywenderlich.com/823-advanced-mapkit-tutorial-custom-tiles – ricardopereira Nov 30 '18 at 20:25
  • no, speaking of clustering, I want to change grid size of that clustering (how far away they are joining together). Or, for example, join red annotations with red, green with green only (with one cluster object) – djdance Dec 02 '18 at 10:32
2

You should have a look into CCHMapClusterController project, looks exactly like something you are looking for.

Kris
  • 5,714
  • 2
  • 27
  • 47
  • I've already had a look at this one, thanks. Btw. theres also another clusterer: https://github.com/alexrepty/ARClusteredMapView – kimar Feb 19 '14 at 11:54
  • The ARCClusteredMapView is not ARC ready, wonder why its named ARC..then :) – Kris Feb 19 '14 at 13:34
  • It's called **AR**ClusteredMapView ;-) There's a **C** too much in your comment ;-) But you're right, ARC compatible frameworks, at the first point, look more future-proof – kimar Feb 20 '14 at 13:09
0

One alternative is the MapBox iOS SDK, which is an open source (BSD) library replicating MapKit behavior. It does both annotation clustering and offline map layers.

http://mapbox.com/mobile

incanus
  • 5,100
  • 1
  • 13
  • 20