简体   繁体   English

如何在Apple MapKit中处理KMZ文件

[英]How to handle KMZ files in Apple's MapKit

I am trying to pull some KMZ files over the net and overlay them on Google Maps. 我正在尝试通过网络提取一些KMZ文件并将其覆盖在Google地图上。 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. 我看过Apple的kmlParser示例,它非常接近我想做的事,但是以当前形式,它只能解析KML文件。 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). 网络上的大多数RSS feed和google数据似乎都是KMZ格式的(我相信这是KML文件的压缩版本)。 Is it possible to unzip the KMZ files programmatically in Xcode? 是否可以在Xcode中以编程方式解压缩KMZ文件?

- (void)viewDidLoad

{ [super 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. 在上面的代码片段中,我也尝试使用NSURL方法(注释掉了几行),但是它不起作用。 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. 我必须手动下载KMZ文件,将其解压缩,然后将其输入到KML解析器中,理想情况下,我想在程序本身中执行此操作。

I will appreciate any help or guidance on how to solve this problem. 我将感谢您提供有关如何解决此问题的帮助或指导。

Soofi Soofi

hey i would like to recommend KML Viewer , 嘿,我想推荐KML Viewer,

just download the project and you will find everything there 只需下载项目,您将在其中找到所有内容

link : KML Viewer 链接: KML查看器

i know this ans is late but its for people who want reference :) 我知道这ans已经晚了,但是对于想要参考的人来说是这样的:)

You are right that KMZ files are simply zipped up KML files. 没错,KMZ文件只是压缩了KML文件。 The appropriate part of the documentation is here . 文档的适当部分在此处

The Apple KML example is very simplistic. Apple KML示例非常简单。 If you want a fuller featured parser, I would recommend libKML . 如果您需要功能更全面的解析器,建议使用libKML It has full support for the KML standard, and handles KML and KMZ files. 它完全支持KML标准,并处理KML和KMZ文件。 The only catch is that it is written in C++, and uses intrusive pointers which can be a bit painful in Obj-C. 唯一的问题是它是用C ++编写的,并且使用侵入性指针,这在Obj-C中可能会有些痛苦。

If you really want to write your own parser, and just need a way to unzip files, ZipKit should work for you. 如果您确实想编写自己的解析器,并且只需要一种解压缩文件的方法,则ZipKit应该适合您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM