我已经从GMapCatcher下载了一些图块,并尝试使用MKTileOverlay在我的项目中实现它们。请参见下面的代码。我不断收到未理解的图块的多个错误。捆绑包的路径是正确的,我已将图块放置在项目中。地图用黑色瓷砖渲染。
请问有人可以亮起
导入UIKit 导入MapKit
ViewController类:UIViewController,MKMapViewDelegate {
@IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
super.viewDidLoad()
self.mapView.delegate = self
let baseURL = Bundle.main.bundleURL.absoluteString
let urlTemplate = baseURL.appendingFormat("OSM_tiles/{z}/{x}/{y}.png")
//OSM_sat_tiles is the folder name which has the tiles.
let layer = MKTileOverlay(urlTemplate: urlTemplate)
layer.canReplaceMapContent = true
self.mapView.addOverlay(layer)
}
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
if overlay is MKTileOverlay {
let renderer = MKTileOverlayRenderer(overlay:overlay)
renderer.alpha = 0.8
return renderer
}
return MKTileOverlayRenderer(overlay: overlay)
}
}
错误消息之一:
:加载URL文件:/// Users / CM / Library / Developer / CoreSimulator / Devices / 9394F962-B95D-4F7A-845F-EBCA1BF2C4BA / data / Containers / Bundle / Application / 415B5B22-D335-4E62-BEC8- 6EB8AC00E8D5 / OSMTileOverlayDemo.app / OSM_tiles / 8/168 / 112.png:错误域= NSURLErrorDomain代码= -1100“在此服务器上找不到请求的URL。” UserInfo = {NSUnderlyingError = 0x6000008a7cf0 {Error Domain = kCFErrorDomainCFNetwork Code = -1100“(null)”},NSErrorFailingURLStringKey = file:/// Users / CM / Library / Developer / CoreSimulator / Devices / 9394F962-B95D-4F7A-845F-EBCA1BF2C4 /data/Containers/Bundle/Application/415B5B22-D335-4E62-BEC8-6EB8AC00E8D5/OSMTileOverlayDemo.app/OSM_tiles/8/168/112.png,NSErrorFailingURLKey = file:/// Users / CM / Library / Developer / CoreSimulator / Devices / 9394F962-B95D-4F7A-845F-EBCA1BF2C4BA / data / Containers / Bundle / Application / 415B5B22-D335-4E62-BEC8-6EB8AC00E8D5 / OSMTileOverlayDemo.app / OSM_tiles / 8/168 / 112.png,NSLocalizedDescription =请求的URL是在此服务器上找不到。}