如何在 iOS 的 GoogleMaps 中使用自定义标记进行标记聚类?

How to make marker clustering with custom markers in GoogleMaps for iOS?

我是 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() {...}

您可以查看以下主题:

你会找到一个很好的答案,因为我上周遇到了同样的问题,只要遵循这些建议即可。 希望对你有很大帮助