How to clustered markers from Firebase in GoogleMaps for iOS

后端 未结 2 1731
暗喜
暗喜 2020-12-20 10:26

I\'m developing an app on which I want to show a lot of events on the map. The user can click on an event and see a lot of informations about it. In another view, a user can

2条回答
  •  我在风中等你
    2020-12-20 11:27

    Firstly loadMarker() should be called after the clusterManager is initialized i.e

    clusterManager = GMUClusterManager(map: maMap, algorithm: algorithm, renderer: renderer)
    

    then

    clusterManager.cluster()
    clusterManager.setDelegate(self, mapDelegate: self)
    

    should be placed in loadMarker() after for loop ends.

    Your viewcontroller should conform to this protocol GMUClusterManagerDelegate then add these 2 methods in viewcontroller.

    func renderer(_ renderer: GMUClusterRenderer, markerFor object: Any) -> GMSMarker? {
    
        let marker = GMSMarker()
        if let model = object as? MarkerModel {
             // set image view for gmsmarker
        }
    
        return marker
    }
    
    func clusterManager(_ clusterManager: GMUClusterManager, didTap cluster: GMUCluster) -> Bool {
        let newCamera = GMSCameraPosition.camera(withTarget: cluster.position, zoom: mapView.camera.zoom + 1)
        let update = GMSCameraUpdate.setCamera(newCamera)
        mapView.moveCamera(update)
        return false
    }
    

    Try this and let me know if this works else we will try something else.

提交回复
热议问题