如何以编程方式在ios7中更改地图颜色

问题描述:

我正在使用iOS 7的应用程式,并尝试将地图从白天改变为黑夜,改为白天改变。我没有在iOS 7文档中找到任何相关的API。

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.

这不是 MKMapKit 所以你问的是不可能没有你自己。如果你自己做,最好的办法是找到一个夜间模式地图的地图瓦片源,并使用 MKTileOverlay 类(新建到iOS 7)来完全替换地图的内容。

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];
    }
}

有关完整参考,请参阅 https://developer.apple.com/library/ios/documentation/MapKit /Reference/MKTileOverlay_class/Reference/Reference.html

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