一个超简单的 SAX kml 解析器 - 非常适合处理大型 kml 文件
要运行示例项目,首先克隆存储库,然后从示例目录运行 pod install
。
#import "Kml.h"
//...
-(void) someKmlIntializer:(NSString *) kmlText{
NSString *kmlString=@"<?xml version=\"1.0\" encoding=\"UTF-8\"?><kml xmlns=\"http:/www.opengis.net/kml/2.2\"><Placemark><name>Descriptive HTML</name><visibility>1</visibility><description><![CDATA[]]></description><Point><coordinates>-122.0822035425683,37.42228990140251,0</coordinates></Point></Placemark></kml>";
Kml *kml =[[Kml alloc] initWithKmlString:kmlString];
[kml onPlacemark:^(NSDictionary *dictionary) {
//NSLog(@"%@", dictionary);
}];
[kml parse];
}
#SomeViewController.h
...
#import "SaxKmlParserDelegate.h"
@interface SomeViewController : UIViewController<SaxKmlParserDelegate, ...>
...
#SomeViewController.m
...
-(void) someKmlIntializer:(NSString *) kmlText{
[[[SaxKmlParser alloc] initWithDelegate:self] parseString:kmlText];
}
-(void) onKmlPlacemark:(NSDictionary *)dictionary{
//TODO add to MKMap
}
-(void) onKmlGroundOverlay:(NSDictionary *)dictionary{
//TODO add to MKMap
}
-(void) onKmlPolyline:(NSDictionary *)dictionary{
//TODO add to MKMap
}
-(void) onKmlPolygon:(NSDictionary *)dictionary{
//TODO add to MKMap
}
...
KMLSaxParser 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod "KMLSaxParser"
nickolanack,[email protected]
KMLSaxParser 使用 MIT 许可证提供。有关更多信息,请参阅 LICENSE 文件。