Hi!
Years ago Apple created an MKMapView demo called KMLViewer. It includes a KMLParser that reads a KML file and converts the data to Map Kit classes.
Originally it was in Obj. C, but someone translated it to Swift, and put it here:
https://github.com/ooper-shlab/KMLViewer-Swift
I imported it directly into Xcode and made it read a KML file I have created.
It correctly finds 10 overlays in the form of MKPolyline and 11 annotations in the form of MKPointAnnotation, but they are not shown/displayed correctly.
The biggest problem is that the lines are totally missing. And when I look at the overlays I can't seem to find the 2 geographic points/positions/locations that describes each line.
I am not sure how to make Xcode print out the content of the MKPolyline(s) instances in a way I can include here as text, and it seems you can't attach a screenshot here either, but I have managed to put the screenshot here: transformation.dk/deling/screenshot-overlays-MKPolyline-2021-05-13.png
So you can see the content as I found it. It seems to correctly indicate that the MKPolyline consists of 2 geographic points, but I haven't been able to find the points themselves...
On the annotations I was able to find the point, in the Xcode debugger, in this way:
(lldb) po annotations[0].coordinate
I hope someone can help me understand what is going on, and how to find the relevant debugging/tracking information in Xcode.
I am a bit surprised that I had to specifically write ".coordinate" in "po annotations[0].coordinate" in order to find the geographic point of the annotation!
I am aware that the problem might also be the MKPolylineRenderer class or the mapView:rendererForOverlay: method, so I have included the references to those in KMLviewer below:
swift
override func createOverlayPathRenderer(_ shape: MKShape) - MKOverlayPathRenderer? {
let polyLine = MKPolylineRenderer(polyline: shape as! MKPolyline)
return polyLine
}
(EDIT: PS: The following code was display incorrectly in the preview...:)
swift
func rendererForOverlay(_ overlay: MKOverlay) - MKOverlayRenderer? {
// Find the KMLPlacemark object that owns this overlay and get
// the view from it.
for placemark in _placemarks {
if placemark.overlay === overlay {
return placemark.overlayPathRenderer
}
}
return nil
}