ios - MapKit Tile Overlay 在 iOS8 中损坏

标签 ios objective-c ios8 mapkit openstreetmap

我有这段代码可以在我的应用程序中通过默认的 Apple 应用程序实现 OSM:

dispatch_async(dispatch_get_main_queue(), ^{
    NSString *template = @"http://tile.openstreetmap.org/{z}/{x}/{y}.png";
    MKTileOverlay *overlay = [[MKTileOverlay alloc] initWithURLTemplate:template];
    overlay.canReplaceMapContent = YES;
    [self.mapView addOverlay:overlay level:MKOverlayLevelAboveLabels];});

和:

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {
if ([overlay isKindOfClass:[MKTileOverlay class]]) {
    return [[MKTileOverlayRenderer alloc] initWithTileOverlay:overlay];
}
else return nil;
}

在 iOS 7 中它很好,但现在它返回多次并且根本没有加载 map :

<Error>: ImageIO: CGImageSourceCreateWithData data parameter is nil

我该如何解决?我试图重构我的代码,所以第一 block 代码现在是:

dispatch_queue_t fetchTiles = dispatch_queue_create("fetcher", NULL);
dispatch_async(fetchTiles, ^{
    NSString *template = @"http://tile.openstreetmap.org/{z}/{x}/{y}.png";
    MKTileOverlay *overlay = [[MKTileOverlay alloc] initWithURLTemplate:template];
    overlay.canReplaceMapContent = YES;
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.mapView addOverlay:overlay level:MKOverlayLevelAboveLabels];});});

但这似乎并不能解决问题。

最佳答案

您使用的代码看起来不错,除了...

您在 block 中添加叠加层似乎很奇怪。我只是添加了一个 Action ,它似乎根本没有挂起 UI。

只是做...

    NSString *template = @"http://tile.openstreetmap.org/{z}/{x}/{y}.png";
    MKTileOverlay *overlay = [[MKTileOverlay alloc] initWithURLTemplate:template];
    overlay.canReplaceMapContent = YES;
    [self.mapView addOverlay:overlay level:MKOverlayLevelAboveLabels];

此外,我向 Apple 提交了一个错误,当他们想要一个示例时,我的叠加层不会显示...直到我设置委托(delegate)。 (即使我在 Storyboard中有线)。 Apple 将我的错误作为副本关闭,以便他们知道。

mapView.delegate = self

关于ios - MapKit Tile Overlay 在 iOS8 中损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25124452/

相关文章:

ios - 自定义单元格未显示

ios - 无法返回 - popViewController 动画无法正常工作,向后滑动也无法正常工作

ios - 点击单元格时表格 View 单元格会更改高度

ios - 当 showsScopeBar=YES 时,iOS8 上的 UISearchBar 高度

ios - 无法在 SwiftUI 的当前上下文中推断闭包类型

ios - RxSwift 网络状态可观察

iphone - Pinterest 在 iOS 应用程序中的集成?

ios - 如何访问下载的解压文件夹中的图像?

objective-c - 如何通过拖放文件来启动非基于文档的 Cocoa 应用程序?

ios8 - 从 native 应用程序到网站的切换不起作用