I am trying to create an app that uses the MapKit and I want to create annotations on the map, but I am struggling to put images on the map annotations.
I am a beginner with Swift programming, I have been working off this tutorial, but I can't find anywhere online that helps you implement an image, most guides are using Objective C.
This is my annotation class, which is called in my View Controller.
Note: I have my little image I want to be shown in my images.xcassets folder as "mapAnnotation"
let buildingName = location(title: "Building Name",
locationName: "Location",
coordinate: CLLocationCoordinate2D(latitude: NUMBER, longitude: NUMBER))
theMapview.addAnnotation(buildingName)
Here is the annotation class...
class location: NSObject, MKAnnotation {
let title: String
let locationName: String
let coordinate: CLLocationCoordinate2D
//Retrieve an image
var image = UIImage(named: "mapAnnotation")
init(title: String, locationName:String, coordinate: CLLocationCoordinate2D) {
self.title = title
self.locationName = locationName
self.coordinate = coordinate
self.image
super.init()
}
var subtitle: String {
return locationName
}
}