[!] The 'Pods-MyApp' target has transitive dependencies that include static binaries: (/Users/khoa/Projects/MyApp/Pods/GoogleMaps/Base/Frameworks/GoogleMapsBase.framework, /Users/khoa/Projects/MyApp/Pods/GoogleMaps/Maps/Frameworks/GoogleMaps.framework, and /Users/khoa/Projects/MyApp/Pods/GoogleMaps/Maps/Frameworks/GoogleMapsCore.framework)
Add ClusterItem
1 2 3 4 5 6 7 8 9 10 11 12
import Foundation import CoreLocation
classClusterItem: NSObject, GMUClusterItem{ let position: CLLocationCoordinate2D let stop: Stop init(stop: Stop) { self.stop = stop self.position = stop.toCoordinate() } }
Set up cluster manager
1 2 3 4 5 6
let iconGenerator = GMUDefaultClusterIconGenerator() let algorithm = GMUNonHierarchicalDistanceBasedAlgorithm() let renderer = GMUDefaultClusterRenderer(mapView: mapView, clusterIconGenerator: iconGenerator) renderer.delegate = self clusterManager = GMUClusterManager(map: mapView, algorithm: algorithm, renderer: renderer) clusterManager.setDelegate(self, mapDelegate: self)
A simple clustering algorithm with O(nlog n) performance. Resulting clusters are not * hierarchical. * High level algorithm: * 1. Iterate over items in the order they were added (candidate clusters). * 2. Create a cluster with the center of the item. * 3. Add all items that are within a certain distance to the cluster. * 4. Move any items out of an existing cluster if they are closer to another cluster. * 5. Remove those items from the list of candidate clusters. * Clusters have the center of the first element (not the centroid of the items within it).
Make ClusterItem and add to clusterManager. In the end, call clusterManager.cluster()