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

发布于 2024-11-07 01:43:54 字数 1103 浏览 1 评论 0原文

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

- (void)viewDidLoad

{ [超级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 解析器,理想情况下我想在程序本身中执行此操作。

对于如何解决此问题的任何帮助或指导,我将不胜感激。

苏菲

I am trying to pull some KMZ files over the net and overlay them on Google Maps. I have looked at Apple's kmlParser example, which is very close to what I want to do, however in its current form it can only parse KML files. Most of the RSS feeds and google data on the net however seems to be in KMZ format (which I believe is a zipped version of KML files). Is it possible to unzip the KMZ files programmatically in Xcode?

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

In the above code snipped, I have also tried using the NSURL method (commented out lines), but it doesn't work. I have to manually download the KMZ file, unzip it and then feed it to the KML parser and ideally I would like to do that within the program itself.

I will appreciate any help or guidance on how to solve this problem.

Soofi

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷弦 2024-11-14 01:43:54

嘿,我想推荐 KML 查看器,

只需下载该项目,您就会在

链接中找到所有内容:KML 查看器

我知道这个答案已经晚了,但它是为那些想要参考的人准备的:)

hey i would like to recommend KML Viewer ,

just download the project and you will find everything there

link : KML Viewer

i know this ans is late but its for people who want reference :)

冬天旳寂寞 2024-11-14 01:43:54

您是对的,KMZ 文件只是压缩的 KML 文件。文档的相应部分位于此处

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

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

You are right that KMZ files are simply zipped up KML files. The appropriate part of the documentation is here.

The Apple KML example is very simplistic. If you want a fuller featured parser, I would recommend libKML. It has full support for the KML standard, and handles KML and KMZ files. The only catch is that it is written in C++, and uses intrusive pointers which can be a bit painful in Obj-C.

If you really want to write your own parser, and just need a way to unzip files, ZipKit should work for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文