我阅读了本教程Apple kml viewvwer文章。它可以帮助我加载 kml,但是当我也加载图像时。我创建文件夹名称文件并在文件夹中写入png图像..在kml文件中,使用图像参考..这是代码
self.archive = [ZKDataArchive archiveWithArchivePath:archivePath];
[self.archive inflateAll];
for (int i =0;i < [self.archive.inflatedFiles count]; i++) {
NSDictionary *fileDict = [self.archive.inflatedFiles objectAtIndex:i];
NSData *fileData = [fileDict objectForKey:ZKFileDataKey];
NSString *fileName = [fileDict objectForKey:ZKPathKey];
NSString *ext = [fileName pathExtension];
NSString* fileToSaveTo;
if([fileName isEqualToString:@"doc.kml"])
{
fileToSaveTo = fileName;
NSArray* path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString* documentsDirectory = [path objectAtIndex:0];
NSLog(@"%@",documentsDirectory);
[fileData writeToFile:[NSString stringWithFormat:@"%@/%@",documentsDirectory,fileToSaveTo] atomically:YES];
}
else{
fileToSaveTo = [fileName substringFromIndex:6];
NSLog(@"%@",fileToSaveTo);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
// Get documents folder
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"files"];
NSLog(@"%@",documentsDirectory);
[fileData writeToFile:[NSString stringWithFormat:@"%@/%@",dataPath,fileToSaveTo] atomically:YES];
}
}
但我在地图上看不到图像。图像在文档中是安全的,并且 kml 文件读取完美......但我也想显示图像:(