我正在使用以下代码将自定义地图图块加载到我的应用程序中。当我使用 mainBundle 作为路径时,它按预期工作:
NSString *baseURL = [[[NSBundle mainBundle] bundleURL] absoluteString];
NSString *urlTemplate = [baseURL stringByAppendingString:@"/tiles/{z}/{x}/{y}.png"];
self.tileOverlay = [[MKTileOverlay alloc] initWithURLTemplate:urlTemplate];
self.tileOverlay.canReplaceMapContent=YES;
[self.mapView insertOverlay:self.tileOverlay belowOverlay:self.gridOverlay];
但是,如果我尝试更改文档文件夹的路径(因为我打算下载瓷砖文件夹并将它们存储在文档文件夹中),则以下代码不起作用:
NSString *destinationPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *urlTemplate = [destinationPath stringByAppendingString:@"tiles/{z}/{x}/{y}.png"];
self.tileOverlay = [[MKTileOverlay alloc] initWithURLTemplate:urlTemplate];
self.tileOverlay.canReplaceMapContent=YES;
[self.mapView insertOverlay:self.tileOverlay belowOverlay:self.gridOverlay];
任何提示都会很有用!
注意: tiles 文件夹存在于我的路径中。更具体地说,以下代码返回 YES
NSString* foofile = [destinationPath stringByAppendingPathComponent:@"/tiles/17/70759/49235.png"]; //as an example
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:foofile];