Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

count on cluster item #11

Closed
MaeseppTarvo opened this issue Jun 21, 2017 · 5 comments
Closed

count on cluster item #11

MaeseppTarvo opened this issue Jun 21, 2017 · 5 comments

Comments

@MaeseppTarvo
Copy link

Hey! How should you add the count to cluster item?

@maxep
Copy link
Contributor

maxep commented Jun 24, 2017

You can manage the cluster UI in the mapview's data source method.

  • MKMapView:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

    if let cluster = annotation as? CKCluster {
         // Return an annotation view that show the cluster count.
    }
}
  • GMSMapView:
func mapView(_ mapView: GMSMapView, markerFor cluster: CKCluster) -> GMSMarker {
    let marker = GMSMarker(position: cluster.coordinate)
    marker.iconView = // Set a view that show the cluster count.
    return marker;
}

@MaeseppTarvo
Copy link
Author

@maxep I created simple UILabel and assigned it to the iconView but the count is totally wrong for some reason. Is the cluster.count right?

@maxep
Copy link
Contributor

maxep commented Jul 25, 2017

@MaeseppTarvo yes you can use the count property, I'm not seeing a wrong value on my side.

@NSMyself
Copy link

NSMyself commented Aug 9, 2017

@MaeseppTarvo I tried adding a label as a subview to the annotationView of the example project and I was experiencing the same issue: the label was off by a lot (and it persisted even when the annotation wasn't a cluster).

If you disable the annotation reuse it works though.

@maxep
Copy link
Contributor

maxep commented Aug 11, 2017

Did you properly clean the count label of the reused view? whether in the prepareForReuse of the annotation view subclass, or in the data source method mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation)

@maxep maxep closed this as completed Sep 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants