Hello,
when I add some thousands simple annotations to a MKMapView, and complie & run the code with XCode 9 everything works as expected: smooth and well performing without any delays (at least with 5000 annotations on a MacBook Pro Late 2016).
However same code executed on XCode 10 or XCode 11 is no longer smooth until all annotations were loaded once. Which takes after some scrolling on the map 30 to 60 seconds.
My actual applicaiton requires many annotations which is no problem when compiling with XCode 9.
Is there a chance to get this also smooth after compiled with current XCode?
Or is this some general MapKit change under the hood?
And hep is appreciated.
Here my code:
import Cocoa
import MapKit
class ViewController: NSViewController {
@IBOutlet weak var myMapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
var alle = [MKPointAnnotation]()
for _ in 1...3000 {
let randomx = Double(arc4random()) / 0xFFFFFFFF //value between 0 ... 1
let randomy = Double(arc4random()) / 0xFFFFFFFF //value between 0 ... 1
let lat = randomx * 100.0 - 50.0 // Value between -50.0 ... 50.0
let lon = randomy * 100.0 - 50.0 // Value between -50.0 ... 50.0
let annotation = MKPointAnnotation()
annotation.coordinate = CLLocationCoordinate2D(latitude: lat, longitude: lon)
alle.append(annotation)
}
print ("Array contains now \(alle.count) annotations")
myMapView.addAnnotations(alle)
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard annotation is MKPointAnnotation else { return nil }
let identifier = "Annotation"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
if annotationView == nil {
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
annotationView!.canShowCallout = true
} else {
annotationView!.annotation = annotation
}
return annotationView
}
}