I have the following test code. It’s supposed to show an image on a map view. The image is not showing. I get no errors. I wonder if I made a mistake where I use the context where I scale or translate or draw. Would anyone help me out with this?
import UIKit
import MapKit
import CoreText
class LabelOverlayRenderer: MKOverlayRenderer {
override func draw(_ mapRect: MKMapRect, zoomScale: MKZoomScale, in context: CGContext) {
let image = UIImage(named: "myImage.png")!
let imageReference = image.cgImage!
let theMapRect = overlay.boundingMapRect
let theRect = rect(for: theMapRect)
context.scaleBy(x: 1, y: -1)
context.translateBy(x: 0, y: -theRect.size.height)
context.draw(imageReference, in: theRect)
}
}
import UIKit
import MapKit
class LabelOverlay: NSObject, MKOverlay {
var coordinate: CLLocationCoordinate2D
var boundingMapRect: MKMapRect
var string: String
init(coordinate: CLLocationCoordinate2D, string: String) {
self.coordinate = coordinate
let mapPoint = MKMapPointForCoordinate(coordinate)
let mapSize = MKMapSize(width: 50, height: 21)
boundingMapRect = MKMapRect(origin: mapPoint, size: mapSize)
self.string = string
}
}