Reputation: 53
I was attempting to test an app on the Xcode 11 simulator that used CoreLocation. I wanted to use the "Freeway Drive" location option in the simulator under Debug > Location to test the MapKit polyline overlay.
Unfortunately, no line was placed on the map and "Compiler error: Invalid library file" was printed numerous times in the log.
It does not seem to be a code problem but more of an Xcode problem. Is there any way around this? It is very difficult to test with a physical device because movement in a confined space doesn't really pick up with CoreLocation.
Thanks!
Upvotes: 3
Views: 1891
Reputation: 53
just define the polyline and "push" it into your mapView:
let polyline = MKPolyline(coordinates: locations, count: locations.count)
mapView.addOverlays([polyline])
and declare the mkMapViewDelegate's function:
//MKMapViewDelegate
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) ->
MKOverlayRenderer
{
if let mapPolyline = overlay as? MKPolyline {
let polyLineRenderer = MKPolylineRenderer(polyline: mapPolyline)
polyLineRenderer.strokeColor = .darkGray
polyLineRenderer.lineWidth = 4.0
return polyLineRenderer
}
fatalError("Polyline Renderer could not be initialized" )
}
It should show the polyline on the mapView. I have the compiler error too and try to fix it.
Best Dragan
Upvotes: 2