iOSのMKMapViewでタイル表示

iOSのMKMapViewでApple Mapではなく他のタイルサーバー(OSM)を使用するにはMKMapViewのオーバーレイ機能を使用する。

MKMapView *mv = [[[MKMapView alloc]initWithFrame:rect]autorelease];
[mv setMapType:MKMapTypeStandard];
[mv setDelegate:self];
    
NSString *template = @"http://tile.openstreetmap.org/{z}/{x}/{y}.png";
MKTileOverlay *overlay = [[MKTileOverlay alloc] initWithURLTemplate:template];
overlay.canReplaceMapContent = YES;
[mv addOverlay:overlay level:MKOverlayLevelAboveLabels];
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {
    if ([overlay isKindOfClass:[MKTileOverlay class]]) {
        return [[MKTileOverlayRenderer alloc] initWithTileOverlay:overlay];
    }
    return nil;
}