Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically change map color from day to night in ios7

I am working on an app for iOS 7, and am trying to change the map from day to night and night to day mode. I have not found any relevant APIs in iOS 7 documentation to do this.

like image 902
user2001457 Avatar asked Feb 24 '14 18:02

user2001457


1 Answers

This is not a built in feature of MKMapKit so what you are asking is not possible without doing it yourself. If you were going to do it yourself, the best you could do would be to find a map tile source of 'night mode' tiles, and use the MKTileOverlay class (New to iOS 7) to replace the content of the map entirely.

A brief code example using the Open Street Map tile source (Not night tiles!)

// Put this in your -viewDidLoad method
NSString *template = @"http://tile.openstreetmap.org/{z}/{x}/{y}.png";
MKTileOverlay *overlay = [[MKTileOverlay alloc] initWithURLTemplate:template];

//This is the important bit, it tells your map to replace ALL the content, not just overlay the tiles.
overlay.canReplaceMapContent = YES;
[self.mapView addOverlay:overlay level:MKOverlayLevelAboveLabels];

Then implement the mapView delegate method below...

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {
    if ([overlay isKindOfClass:[MKTileOverlay class]]) {
        return [[MKTileOverlayRenderer alloc] initWithTileOverlay:overlay];
    }
}

For full reference, see https://developer.apple.com/library/ios/documentation/MapKit/Reference/MKTileOverlay_class/Reference/Reference.html

like image 129
Sammio2 Avatar answered Nov 05 '22 16:11

Sammio2