I want to be able to store a custom value for each dropped pin using MKPointAnnotation
. Specifically, I want to store some id with each pin and retrieve at calloutAccesoryControlTapped
.
Asked
Active
Viewed 1,073 times
0
-
Is this a question on how to persist data, or on how to do something with MapKit? What do you mean by "store a custom value"? – Daniel T. Dec 14 '15 at 01:31
2 Answers
3
You'll have to subclass MKPointAnnotation with a property to store this custom value (I named it tag)
import UIKit
import MapKit
class CustomPointAnnotation: MKPointAnnotation {
var tag: Int!
}
Creating pins:
let annotation = CustomPointAnnotation()
annotation.coordinate = CLLocationCoordinate2D(latitude: CLLocationDegrees(latitude), longitude: CLLocationDegrees(longitude))
annotation.title = [insert name]
annotation.tag = [insert tag]
self.mapView.addAnnotation(annotation)
And in your mapView delegate's viewForAnnotation, after checking the dequeableAnnotation you do:
if (annotation is CustomPointAnnotation) {
pinView?.tag = (annotation as! CustomPointAnnotation).tag
}

Marcos Griselli
- 1,306
- 13
- 22