In my code I'm adding a single pin to the map. So far I'm doing it like that:
let pinLocation = CLLocationCoordinate2D(
latitude: locationTemp.latitude,
longitude: locationTemp.longitude
)
let annotation = MKPointAnnotation()
annotation.coordinate = pinLocation
self.map.addAnnotation(annotation)
But now, since I want to create a custom pin image, I've read I have to switch to MKAnnotationView
. But I don't know how to set the location of this annotation so that it shows the same annotation as my previous pin.
I tried this:
var pinView = MKAnnotationView()
pinView.image = UIImage(named:"MyCustomPin")
but I cannot find a way of setting here my locationTemp
data.
If you check out the documentation and you'll see MKAnnotationView has an init method
init(annotation annotation: MKAnnotation?, reuseIdentifier reuseIdentifier: String?)
So there's the link between the view and the co-ordinates.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.