KML Parsing Library Released for Apple's iOS Platform

Blog

Estimated
2 min read

I’ve been working this summer with the MapBox team on bringing interactive mapping to the iPad (expect another post soon about this work :-) ). In addition to being able to package MapBox tile sets as base layer maps, we need to be able to visualize live data on these maps, so we are supporting KML and GeoRSS. These are each file formats for exchanging geographic information along with content.

GeoRSS is pretty straightforward — it’s basically regular RSS but with a small amount of geographic information added in the form of extra tags such as <georss:point>. KML, however, is a completely different sort of format, written from the ground up for geographic data. It's probably most commonly known as the format that Google Earth uses to exchange geo info. Beyond Google Earth, it has been used in some exciting applications from Development Seed's own Maps on a Stick tool to the Jane Goodall Institute's Gombe Chimpanzee Blog, which attaches KML data to every blog entry as a way to give it context and allow the reader to explore the story a bit more.

Once I got started on the iPad work, however, I noticed that there basically was no parsing library for KML on Apple’s iOS platform — iPhones and iPads. Google puts out the definitive library — libkml. It’s written in C++ (a minor setback), but it also depends on libexpat, something that exists on Mac OS X but not on iOS.

That aside, I thought that it would also be nice to have a Cocoa-native KML parsing library, something that speaks in native Objective-C types like UIImage for icons and UIColor for colors without the need for conversion. So I wrote one!

This library, Simple KML, is now available as open source under the New BSD License, licensed jointly by Development Seed and Code Sorcery Workshop. You can find a basic usage overview in the features summary.

While Simple KML does make KML very simple to parse, it does not do any drawing for you. It’s important to note that you will have to take the placemarks, styles, and structures in the KML documents that you wish to display and write your own drawing to display them. This could be on Apple’s MapKit mapping library built into the SDK, external mapping libraries, or perhaps your own drawing on static map images. Simple KML just makes it easy to turn a KML file or a KMZ archive into data structures native to Cocoa for use in your own graphics work.

I’d love to have any feedback or contributions that you might have to offer. Simple KML is up on GitHub, allowing anyone to create a free account, fork the project, and send me patches via merge requests.

What we're doing.

Latest