MKMapView clustering if too many Map Pins nearby
Asked Answered
T

3

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!

Titleholder answered 30/3, 2013 at 16:39 Comment(1)
Apple have provided the example for doing this thing: Please checkout apple's own example over here: developer.apple.com/library/ios/samplecode/PhotoMap/…Phobos
R
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

Ratsbane answered 25/8, 2017 at 9:55 Comment(5)
I cannot find clusterAnnotationForMemberAnnotations method in zip above :(Princely
@Princely 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.Ratsbane
Do you know how to manage that "automatic"? I want to change grid sizePrincely
@Princely Grid size? Do you mean the tiles? Have a look at raywenderlich.com/823-advanced-mapkit-tutorial-custom-tilesRatsbane
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)Princely
P
2

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

Parisparish answered 14/2, 2014 at 19:35 Comment(3)
I've already had a look at this one, thanks. Btw. theres also another clusterer: github.com/alexrepty/ARClusteredMapViewTitleholder
The ARCClusteredMapView is not ARC ready, wonder why its named ARC..then :)Parisparish
It's called ARClusteredMapView ;-) There's a C too much in your comment ;-) But you're right, ARC compatible frameworks, at the first point, look more future-proofTitleholder
S
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

Shapely answered 1/4, 2013 at 0:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.