Introduction
Welcome to the documentation for RemarkerClusterer, a library for clustering map markers in iOS apps. Use this documentation as a guide to understand how to integrate RemarkerClusterer into your project, and how to effectively utilize its features.
Installation
To install RemarkerClusterer, follow the steps below:
- Open Terminal and navigate to your project directory.
- Run the following command to integrate RemarkerClusterer using CocoaPods:
pod 'RemarkerClusterer'
Usage
Initializing and Configuring the Cluster Manager
To start using RemarkerClusterer, you need to initialize and configure the cluster manager. Follow the steps below:
- Import the `RemarkerClusterer` module into your source file:
// Swift
import RemarkerClusterer
// Objective-C
@import RemarkerClusterer;
- Create an instance of the `GQTClusterManager`:
let clusterManager = GQTClusterManager()
- Configure the cluster manager with your desired settings:
// Set the maximum zoom level for clustering
clusterManager.maxZoom = 20
// Set the minimum count of markers to activate clustering
clusterManager.minCountForClustering = 2
Adding Markers to the Cluster Manager
Once the cluster manager is initialized and configured, you can start adding markers to it. Follow the steps below:
- Create an array of markers you want to add:
// Swift
let markers: [GQTPoint] = [
GQTPoint(coordinate: CLLocationCoordinate2D(latitude: 37.786996, longitude: -122.440100)),
GQTPoint(coordinate: CLLocationCoordinate2D(latitude: 37.787041, longitude: -122.399456)),
GQTPoint(coordinate: CLLocationCoordinate2D(latitude: 37.773975, longitude: -122.413654))
]
// Objective-C
NSArray *markers = @[
[[GQTPoint alloc] initWithCoordinate:CLLocationCoordinate2DMake(37.786996, -122.440100)],
[[GQTPoint alloc] initWithCoordinate:CLLocationCoordinate2DMake(37.787041, -122.399456)],
[[GQTPoint alloc] initWithCoordinate:CLLocationCoordinate2DMake(37.773975, -122.413654)]
];
- Add the markers to the cluster manager:
clusterManager.add(markers)
Display the Clustered Markers on the Map
To display the clustered markers on the map, follow the steps below:
- Create an instance of `GQTGoogleMapsUtils` and assign it as the delegate of the cluster manager:
// Swift
let googleMapsUtils = GQTGoogleMapsUtils()
clusterManager.setDelegate(googleMapsUtils)
// Objective-C
id googleMapsUtils = [[GQTGoogleMapsUtils alloc] init];
[clusterManager setDelegate:googleMapsUtils];
- Implement the delegate methods for customizing the appearance of the cluster markers:
// Swift
extension YourViewController: GQTClusterManagerDelegate {
func renderer(for cluster: GQTCluster) -> GQTClusterRenderer {
let renderer = YourCustomClusterRenderer()
return renderer
}
}
// Objective-C
@interface YourViewController ()
@end
@implementation YourViewController
- (GQTClusterRenderer *)rendererForCluster:(GQTCluster *)cluster {
YourCustomClusterRenderer *renderer = [[YourCustomClusterRenderer alloc] init];
return renderer;
}
@end
- Render the cluster markers on the map:
googleMapsUtils.render(clusterManager);
Cluster Marker Customization
You can customize the appearance of the cluster markers according to your app’s design. Follow the steps below:
- Subclass `GQTDefaultClusterRenderer`:
// Swift
class YourCustomClusterRenderer: GQTDefaultClusterRenderer {
// Implement custom cluster marker appearance
}
// Objective-C
@interface YourCustomClusterRenderer : GQTDefaultClusterRenderer
@end
@implementation YourCustomClusterRenderer
// Implement custom cluster marker appearance
@end
- Override the necessary methods to customize the appearance:
// Swift
override func shouldRender(as cluster: GQTCluster, atZoom zoom: Float) -> Bool {
// Customize when to render the cluster marker
}
override func style(for cluster: GQTCluster) -> GQTClusterIconStyle {
// Customize the cluster marker style
}
override func icon(for cluster: GQTCluster) -> UIImage {
// Customize the cluster marker icon
}
override func text(for cluster: GQTCluster) -> NSAttributedString {
// Customize the cluster marker text
}
// Objective-C
- (BOOL)shouldRenderAsCluster:(GQTCluster *)cluster atZoom:(float)zoom {
// Customize when to render the cluster marker
}
- (GQTClusterIconStyle *)styleForCluster:(GQTCluster *)cluster {
// Customize the cluster marker style
}
- (UIImage *)iconForCluster:(GQTCluster *)cluster {
// Customize the cluster marker icon
}
- (NSAttributedString *)textForCluster:(GQTCluster *)cluster {
// Customize the cluster marker text
}
Additional Resources
For more information and advanced usage of RemarkerClusterer, refer to the following resources:
Conclusion
Congratulations! You have successfully integrated and utilized RemarkerClusterer in your iOS app. Make sure to refer to the resources provided for any further assistance or advanced usage of the library.