我有这段代码可以在我的应用程序中通过默认的 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/