I'm overriding the loadTileAtPath:result:
method of MKTileOverlay
with the following code. It simply converts the MKTileOverlayPath
into an MKMapRect, and then uses MKMapSnapshotter
to take a snapshot of the map area that's being looked at. From there, I'd do further work using the image of the map. But for now, I'm just returning the snapshots as the resulting data, so I can see how well they represent the map.
- (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);
}];
}
Given that the math here is all correct, in theory it should display a perfect map. Instead, it displays this:
And this is what it should look like (what the map below looks like):