我正在尝试在使用CoreLocation的Xcode 11模拟器上测试一个应用程序。我想使用模拟器中Debug> Location下的“ Freeway Drive”位置选项来测试MapKit折线叠加层。
不幸的是,地图上没有放置任何行,并且在日志中多次打印了“编译器错误:无效的库文件”。
这似乎不是代码问题,而更多是Xcode问题。有没有办法解决?用物理设备进行测试非常困难,因为在有限的空间中移动并不会真正通过CoreLocation进行。
谢谢!
只需定义折线,然后将其“推”到您的mapView中:let polyline = MKPolyline(coordinates: locations, count: locations.count)
mapView.addOverlays([polyline])
并声明mkMapViewDelegate的函数:
//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" )
}
它应该在mapView上显示折线。我也遇到了编译器错误,请尝试修复它。
最佳德拉甘