###REMarkerClusterer creates and manages per-zoom-level clusters for large amounts of markers.
As seen in Pinsnap iPhone app. REMarkerClusterer
was inspired by the Apple Photos app on the iPhone, REMarkerClusterer
mimics it's behaviour providing animations for grouping and ungrouping clusters.
The REMarkerClusterer
will group markers into clusters according to their distance from a cluster's center. When a marker is added, the marker cluster will find a position in all the clusters, and if it fails to find one, it will create a new cluster with the marker. The number of markers in a cluster will be displayed on the cluster marker. When the map viewport changes, REMarkerClusterer
will destroy the clusters in the viewport and regroup them into new clusters.
- Xcode 4.3 or higher
- Apple LLVM compiler
- iOS 4 or higher
- ARC
If you are not using ARC in your project, add -fobjc-arc
as a compiler flag for all the files in this project.
Build and run the REMarkerClustererExample
project in Xcode to see REMarkerClusterer
in action.
REMarkerClusterer
requires the MapKit
and CoreLocation
frameworks, so the first thing you'll need to do is include the frameworks into your project.
Now that the framework has been linked, all you need to do is drop files from REMarkerClusterer
folder into your project, and add #include "REMarkerClusterer.h"
to the top of classes that will use it.
REMarkerClusterer *clusterer = [[REMarkerClusterer alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
clusterer.delegate = self;
[clusterer setLatitude:37.786996 longitude:-97.440100 delta:30.03863];
// Set smaller grid size for an iPad
clusterer.gridSize = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone ? 25 : 20;
[self.view addSubview:clusterer];
clusterer.oneItemCaption = @"One item";
clusterer.manyItemsCaption = @"%i items";
NSDictionary *data = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Points" ofType:@"plist"]];
for (NSDictionary *dict in [data objectForKey:@"Points"]) {
REMarker *marker = [[REMarker alloc] init];
marker.markerId = [[dict objectForKey:@"id"] intValue];
marker.coordinate = CLLocationCoordinate2DMake([[dict objectForKey:@"latitude"] floatValue],
[[dict objectForKey:@"longitude"] floatValue]);
[clusterer addMarker:marker];
}
[clusterer zoomToAnnotationsBounds:clusterer.markers];
[clusterer clusterize];
Roman Efimov
Partially based on MarkerClusterer Javascript library by Xiaoxi Wu (http://gmaps-utility-library-dev.googlecode.com)
REMarkerClusterer is available under the MIT license.
Copyright © 2011-2012 Roman Efimov.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.