You're all set!

To start developing, please head over to our developer documentation.

Activate the Google Maps SDK for iOS

To get you started we'll guide you through the Google Developers Console to do a few things first:

  1. Create or choose a project
  2. Activate the Google Maps SDK for iOS
  3. Create appropriate keys
Continue

KML and GeoJSON

This page shows you how to render geographic data in KML and GeoJSON formats, using GMUKMLParser and GMUGeoJSONParser, in conjunction with GMUGeometryRenderer. KML and GeoJSON are popular formats for rendering geographic data such as points, lines, and polygons.

The following screenshot shows some example KML data rendered on a map:

A map with KML data

Prerequisites and notes

The GMUKMLParser and GMUGeoJSONParser are part of the Google Maps SDK for iOS Utility Library. If you haven't yet set up the library, follow the setup guide before reading the rest of this page.

For the full code sample, see the sample apps on GitHub.

Render KML data

To render KML data on a map, create a GMUKMLParser with the path to a KML resource (KML_Sample.kml in this example). Then, create a GMUGeometryRenderer passing the GMUKMLParser instance. Finally, call GMUGeometryRenderer.render(). The following code example shows rendering KML data on a map:

Swift

/** Assume that <Google-Maps-iOS-Utils/GMUGeometryRenderer.h> and
    <Google-Maps-iOS-Utils/GMUKMLParser.h> are in the bridging-header file.
*/
let path = Bundle.main.path(forResource: "KML_Sample", ofType: "kml")
let url = URL(fileURLWithPath: path!)
kmlParser = GMUKMLParser(url: url)
kmlParser.parse()

renderer = GMUGeometryRenderer(map: mapView,
                               geometries: kmlParser.placemarks,
                               styles: kmlParser.styles)

renderer.render()

Objective-C

#import "GMUKMLParser.h"
#import "GMUGeometryRenderer.h"
...
NSString *path = [[NSBundle mainBundle] pathForResource:@"KML_Sample" ofType:@"kml"];
NSURL *url = [NSURL fileURLWithPath:path];
GMUKMLParser *parser = [[GMUKMLParser alloc] initWithURL:url];
[parser parse];
GMUGeometryRenderer *renderer = [[GMUGeometryRenderer alloc] initWithMap:_mapView
                                                              geometries:parser.placemarks
                                                                  styles:parser.styles];
[renderer render];

Render GeoJSON data

To render GeoJSON data on a map, create a GMUGeoJSONParser with the path to a GeoJSON resource (GeoJSON_sample.kml in this example). Then, create a GMUGeometryRenderer, passing the GMUKMLParser instance. Finally, call GMUGeometryRenderer.render(). The following code example shows rendering GeoJSON data on a map:

Swift

/** Assume that <Google-Maps-iOS-Utils/GMUGeometryRenderer.h> and
    <Google-Maps-iOS-Utils/GMUGeoJSONParser.h> are in the bridging-header file.
*/
let path = Bundle.main.path(forResource: "GeoJSON_sample", ofType: "json")
let url = URL(fileURLWithPath: path!)
geoJsonParser = GMUGeoJSONParser(url: url)
geoJsonParser.parse()

renderer = GMUGeometryRenderer(map: mapView, geometries: geoJsonParser.features)

renderer.render()

Objective-C

#import "GMUGeoJSONParser.h"
#import "GMUGeometryRenderer.h"
...
NSString *path = [[NSBundle mainBundle] pathForResource:@"GeoJSON_sample" ofType:@"json"];
NSURL *url = [NSURL fileURLWithPath:path];
GMUGeoJSONParser *parser = [[GMUGeoJSONParser alloc] initWithURL:url];
[parser parse];
GMUGeometryRenderer *renderer = [[GMUGeometryRenderer alloc] initWithMap:_mapView
                                                              geometries:parser.features];
[renderer render];

Send feedback about...

Google Maps SDK for iOS
Google Maps SDK for iOS
Need help? Visit our support page.