我是iOS开发的初学者。 我在我的应用上添加了GoogleMaps,我可以对GoogleMaps的默认标记进行聚类,但是当我通过计算机中的图像自定义标记时,自定义标记无法聚类。 有人可以帮助我在Swift 3中做到这一点吗?
我向您展示了我的代码的一部分:
override func viewDidLoad() {
mapView = GMSMapView(frame: view.frame)
mapView.camera = GMSCameraPosition.camera(withLatitude: 48.898902, longitude: 2.282664, zoom: 12.0)
mapView.mapType = .normal
mapView.delegate = self
view.addSubview(mapView)
if isClustering {
var iconGenerator: GMUDefaultClusterIconGenerator!
if isCustom { // Here's my image if the event are clustered
var images: [UIImage] = [UIImage(named: "m1.png")!, UIImage(named: "m2.png")!, UIImage(named: "m3.png")!, UIImage(named: "m4.png")!, UIImage(named: "m5.png")!]
iconGenerator = GMUDefaultClusterIconGenerator(buckets: [10, 20, 50, 100, 200], backgroundImages: images)
} else {
iconGenerator = GMUDefaultClusterIconGenerator()
}
let algorithm = GMUNonHierarchicalDistanceBasedAlgorithm()
let renderer = GMUDefaultClusterRenderer(mapView: mapView, clusterIconGenerator: iconGenerator)
clusterManager = GMUClusterManager(map: mapView, algorithm: algorithm, renderer: renderer)
clusterManager.cluster()
clusterManager.setDelegate(self, mapDelegate: self)
} else {
}
// Here's my first custom markers (I don't write here others for simple code)
let firstLocation = CLLocationCoordinate2DMake(48.898902, 2.282664)
let marker = GMSMarker(position: firstLocation)
marker.icon = UIImage(named: "pointeurx1") //Apply custom marker
marker.map = mapView
}
func clusterManager() {...}
答案 0 :(得分:0)
您可以查看以下主题: How to cluster custom icons markers in GoogleMaps for iOS How to clustered markers from Firebase in GoogleMaps for iOS
你可以找到一个很好的答案,因为我上周遇到了同样的问题,只需按照这些建议。 希望它对你有很大的帮助