我用下面的代码覆盖了loadTileAtPath:result:
方法。MKTileOverlay
它只是将 转换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);
}];
}
鉴于这里的数学是正确的,理论上它应该显示一个完美的地图。相反,它显示:
这就是它的样子(下图的样子):