我用下面的代码覆盖了MKTileOverlay的loadTileAtPath:result:方法。它只是将MKTileOverlayPath转换为MKMapRect,然后使用MKMapSnapshotter对正在查看的地图区域进行快照。从那里,我将使用地图的图像进行进一步的工作。但现在,我只是将快照作为结果数据返回,这样我就可以看到它们如何很好地表示地图。
- (void)loadTileAtPath:(MKTileOverlayPath)path
result:(void (^)(NSData *data, NSError *error))result
{
double divisions = pow(2, (float)path.z);
MKMapSize tileSize = MKMapSizeMake(MKMapSizeWorld.width / divisions, MKMapSizeWorld.height / divisions);
MKMapPoint tilePoint = MKMapPointMake(path.x * tileSize.width, path.y * tileSize.height);
MKMapRect tileRect = MKMapRectMake(tilePoint.x, tilePoint.y, tileSize.width, tileSize.height);
MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init];
options.mapRect = tileRect;
options.size = CGSizeMake(tileSize.width, tileSize.height);
options.showsBuildings = NO;
options.showsPointsOfInterest = NO;
options.mapType = MKMapTypeStandard;
MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
[snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
result(UIImagePNGRepresentation(snapshot.image), nil);
}];
}相反,它会显示以下内容:

这是它应该看起来的样子(如下图所示):

发布于 2020-11-19 15:36:00
出现"Bad MKMapSnapshotOptions“消息的原因可能是选项中的size不正确。尺寸不能太大(看起来5000px还可以,但1000px太大了)。大小也不能有子像素大小,因此123.4px无效。请确保在生产该尺寸时使用round()。
https://stackoverflow.com/questions/24215974
复制相似问题