简体   繁体   中英

How to use MKTileOverLay in iOS7?

I tried to use tiled map in ios7 using the method that provided in wwdc, but it doesn't appear anything. Anyone has sample code for that? My code is provided below

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.



    NSString *template = @"http://c.tile.openstreetmap.org/{z}/{x}/{y}.png";
    MKTileOverlay *overLay = [[MKTileOverlay alloc] initWithURLTemplate:template];
    overLay.canReplaceMapContent = YES;
    [self.mapView addOverlay:overLay level:MKOverlayLevelAboveLabels];
    [self.mapView setRegion:MKCoordinateRegionMake(CLLocationCoordinate2DMake(37.776884, -122.387255), MKCoordinateSpanMake(0.25, 0.25))];

}

-(MKTileOverlayRenderer *)mapView:(MKMapView*)mapView rendererForOverlay:(id<MKOverlay>)overlay {

    MKTileOverlayRenderer *renderer = [[MKTileOverlayRenderer alloc] initWithOverlay:overlay];
    renderer.alpha = 0.6;
    return renderer;

Did you set your mapView's delegate to self? Because if not, the -rendererForOverlay won't get called.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM