Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
79 lines (45 sloc) 4.48 KB

Simple KML: Cocoa parsing library for Keyhole Markup Language

Simple KML is a simple & lightweight parsing library for KML written in Objective-C for the iOS platform.

It is not meant for drawing, but rather for parsing. That is, it is up to the developer to turn the data structures returned by Simple KML into drawing code, be it for annotations in MapKit, constructs in an external mapping library, drawing paths on a UIImage, or otherwise.

Simple KML is basically an XML parser with smarts about KML. It presents a hierarchical view of KML data and can turn things like Simple KML color definitions into UIColor and text coordinates into CLLocation so that you don't have to.


Simple KML has been designed & built for iOS 3.2 and greater and is currently only tested on the iPad. There's no particular reason it couldn't run on another iOS version or be adapted to Mac OS X; it just hasn't been done yet out of lack of necessity.

Simple KML depends on TouchXML, an Objective-C library for DOM-based XML parsing based on libxml2, and Objective-Zip, a library for working with archive files, both of which are included in the download.


  • Support for most of the base KML entities.

    Basic support for Object, Feature, Placemark, Container, Document, Folder, Geometry, Point, LineString, LinearRing, Polygon, StyleSelector, Style, SubStyle, BalloonStyle, ColorStyle, LineStyle, PolyStyle, and IconStyle.

  • Simple invocation.

    SimpleKML *myKML = [SimpleKML KMLWithContentsOfFile:@"/path/to/file.kml" error:&error]
    SimpleKML *myKML = [SimpleKML KMLWithContentsOfURL:[NSURL URLWithString:@""] error:&error]

  • Support for KMZ archives.

    Currently searches for a top-level KML file in the archive and retrieves icon data for bundled IconStyle entities.

  • Cocoa-native behavior.

    Native types:

    SimpleKMLLineStyle *lineStyle = myPolygon.lineStyle; UIColor *lineColor = lineStyle.color;
    NSArray *polygonPoints = myPolygon.outerBoundary.coordinates; // CLLocation objects
    UIColor *textColor =;
    UIImage *icon =; // planned: automatically apply scale, heading, and parent style color

    Intelligent parsing:

    SimpleKMLStyle *inlineStyle = myPlacemark.inlineStyle; // within <Placemark>
    SimpleKMLStyle *sharedStyle = myPlacemark.sharedStyle; // common to <Document>; no need to reference <StyleUrl>
    SimpleKMLStyle *activeStyle =; // the inline style overrides the shared style

    SimpleKMLGeometry *geometry = myPlacemark.geometry; // <Point>, <Polygon>, <LineString>, etc.
    SimpleKMLPoint *point = myPlacemark.point; // shortcut if <Point> exists for <Placemark>

    Smart error handling:

    NSError *error;
    SimpleKML *myKML = [SimpleKML KMLWithContentsOfFile:@"invalid.kml" error:&error];
    if (error) { NSLog(@"%@", error); } // SimpleKMLParseError: Improperly formed KML (LinearRing has less than four coordinates)


    gdb: po [mySimpleKMLObject source] // protected variable containing original XML source


    SimpleKMLDocument *document = myPlacemark.document;
    NSArray *documentFeatures = document.features;


Include all of the Simple KML files in your Xcode project, as well as the files in the TouchXML and Objective-Zip subdirectories if you don't already use these in your project.

Per TouchXML's installation guide, add /usr/include/libxml2 to your "Header Search Paths" and -lxml2 to your "Other Linker Flags" since TouchXML depends on libxml2.

You'll also need to link against CoreLocation.framework for a couple of the classes since they make use of Core Location constructs.

Plans, needs, bugs, etc.

If you find a bug or want to otherwise contribute, please fork the project on GitHub and contribute that way. In particular, I would like to start adding built-in testing with a library of accompanying KML test files to parse.


Copyright (c) 2010-2011 Code Sorcery Workshop, LLC and Development Seed, Inc.

The Simple KML library should be accompanied by a LICENSE file. This file contains the license relevant to this distribution. If no license exists, please contact Justin R. Miller at <>.

Jump to Line
Something went wrong with that request. Please try again.