I want to create MKPointAnnotaion
's with the identifier
number in the annotation overlay instead of the pin. So a 1
for the first annotation, a 2
for the second annotation, etc.
First, I added an MKPointAnnotation
to the mapView
based on a UILongPressGestureRecognizer
.
With the mapView(_:viewFor:)
I want to style those Annotations. This works to a certain extent but brings us to my problem:
I created a class CustomAnnotation
to add an identifier
to my MKPointAnnotaion:
class CustomAnnotation: MKPointAnnotation {
var identifier: Int!
}
And I set the identifier
when registering UILongPressGesture
:
let annotation = CustomAnnotation()
annotation.identifier = mapView.annotations.count
Then I use mapView(_:viewFor:)
to change the appearance of my MKPointAnnotaion
's. But I do not know how to set annotationView.glyphText
so that it uses the identifier
defined before for every created annotation individually.
extension ViewController: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard annotation is CustomAnnotation else { return nil }
let annotationView = MKMarkerAnnotationView()
annotationView.glyphTintColor = .white
annotationView.glyphText = "44"
return annotationView
}
}