如何在Apple的MapKit中处理KMZ文件

时间:2011-05-14 12:34:11

标签: iphone cocoa-touch ios mapkit

我正在尝试通过网络提取一些KMZ文件并将其覆盖在Google地图上。我查看了Apple的kmlParser示例,这与我想要做的非常接近,但是在目前的形式下它只能解析KML文件。然而,网上的大多数RSS源和谷歌数据似乎都是KMZ格式(我认为它是KML文件的压缩版本)。是否可以在Xcode中以编程方式解压缩KMZ文件?

- (void)viewDidLoad

{     [super viewDidLoad];

// Locate the path to the route.kml file in the application's bundle
// 
//NSURL *path = @"http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-age.kmz";
//NSURL *url = [[NSURL alloc] initWithString:@"http://earthquake.usgs.gov/earthquakes/catalogs/eqs7day-age.kmz"];
//kml = [[KMLParser parseKMLAtURL:url] retain];    // and parse it with the KMLParser.
NSString *path = [[NSBundle mainBundle] pathForResource:@"doc" ofType:@"kml"];
kml = [[KMLParser parseKMLAtPath:path] retain];    // and parse it with the KMLParser.


// Add all of the MKOverlay objects parsed from the KML file to the map.
NSArray *overlays = [kml overlays];
[map addOverlays:overlays];

在上面的代码剪辑中,我也尝试过使用NSURL方法(注释掉的行),但它不起作用。我必须手动下载KMZ文件,将其解压缩然后将其提供给KML解析器,理想情况下我想在程序本身中执行此操作。

我将非常感谢有关如何解决此问题的任何帮助或指导。

Soofi

2 个答案:

答案 0 :(得分:3)

嘿,我想推荐KML Viewer,

只需下载该项目,您就会找到所有内容

link:KML Viewer

我知道这个问题已经很晚了,但是对于那些想要参考的人来说:)

答案 1 :(得分:1)

你是对的,KMZ文件只是压缩KML文件。文档的适当部分是here

Apple KML示例非常简单。如果你想要一个更全面的特色解析器,我会推荐libKML。它完全支持KML标准,并处理KML和KMZ文件。唯一的问题是它是用C ++编写的,并且使用了侵入式指针,这在Obj-C中可能有点痛苦。

如果您真的想编写自己的解析器,并且只需要一种解压缩文件的方法,那么ZipKit应该适合您。