importer ces cadres:
#import <MapKit/MapKit.h>
Inclure ce délégué
@interface ViewController() <MKMapViewDelegate>
Ajouter ce code à votre méthode viewDidLoad pré-existante
(void)viewDidLoad
{
// Tile system URL template goes here
NSString *template = @"http://tile.openstreetmap.org/{z}/{x}/{y}.png";
// Associating overlay with URL template
MKTileOverlay *overlay = [[MKTileOverlay alloc] initWithURLTemplate:template];
// Allowing overlays on MKMapView & disabling Apple map data
overlay.canReplaceMapContent = YES;
// Adding overlay to MKMapView above Apple lables
[self.mapView addOverlay:overlay level:MKOverlayLevelAboveLabels];
// Linking the delegate to allow the next method to be called
self.mapView.delegate = self;
}
Et cela quelque part dans votre classe qui est délégué de Mapview (très probablement un contrôleur de vue).
(MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay
{
if ([overlay isKindOfClass:[MKTileOverlay class]]) {
// Overlay the tile with the new template
return [[MKTileOverlayRenderer alloc] initWithTileOverlay:overlay];
}
return nil;
}