Select platform: [Android](https://developers.google.com/maps/documentation/android-sdk/utility/kml.md.txt "View this page for the Android platform docs.") [iOS](https://developers.google.com/maps/documentation/ios-sdk/utility/kml.md.txt "View this page for the iOS platform docs.") [JavaScript](https://developers.google.com/maps/documentation/javascript/kml.md.txt "View this page for the JavaScript platform docs.")

1. [Introduction](https://developers.google.com/maps/documentation/android-sdk/utility/kml.md.txt#introduction)
2. [Add a KML layer](https://developers.google.com/maps/documentation/android-sdk/utility/kml.md.txt#add)
3. [Clear a KML layer](https://developers.google.com/maps/documentation/android-sdk/utility/kml.md.txt#clear)
4. [Access KML containers](https://developers.google.com/maps/documentation/android-sdk/utility/kml.md.txt#features)
5. [Access KML placemarks and KML ground overlays](https://developers.google.com/maps/documentation/android-sdk/utility/kml.md.txt#containers)
6. [Access KML properties](https://developers.google.com/maps/documentation/android-sdk/utility/kml.md.txt#properties)
7. [KML supported features](https://developers.google.com/maps/documentation/android-sdk/utility/kml.md.txt#supported)

## Introduction


[KML](https://developers.google.com/kml/documentation/kmlreference.md.txt)
is an extension of the
[XML](https://developers.google.com/kml/documentation/kmlreference.md.txt)
data format and represents geographical data on a map. Using this utility, you
can convert KML objects into geographical shapes and render them as a layer on
top of a map. To add and remove your KML data to and from the map, call
`addLayerToMap()` and `removeLayerFromMap()`
respectively. To access properties in a KML object, call
`getProperties()` on any Placemark, GroundOverlay, Document or
Folder.

## Add a KML layer to the map

To add a data layer to the map, first create an instance of the
`KmlLayer` class. There are two ways to instantiate a
`KmlLayer`.

To import and render a KML dataset from a local resource, you need:

- A `GoogleMap` object where the layer is to be rendered.
- A local resource file containing the KML data.
- A `Context` object, which is required to open a local resource file.

### Kotlin

```kotlin
val layer = KmlLayer(map, R.raw.kml_file, context)

      
```

### Java

```java
KmlLayer layer = new KmlLayer(map, R.raw.kml_file, context);

      
```

To import and render a KML dataset from a local stream, you need:

- A `GoogleMap` object where the layer is to be rendered.
- An `InputStream` containing the KML data.
- A `Context` object, which is required to open local resources.

### Kotlin

```kotlin
val inputStream: InputStream = context.resources.openRawResource(R.raw.kml_file)
val layer = KmlLayer(map, inputStream, context)

      
```

### Java

```java
InputStream inputStream = context.getResources().openRawResource(R.raw.kml_file);
KmlLayer layer = new KmlLayer(map, inputStream, context);

      
```

After you have created a `KmlLayer`, call
`addLayerToMap()()` to add the imported data onto the map.

### Kotlin

```kotlin
layer.addLayerToMap()

      
```

### Java

```java
layer.addLayerToMap();

      
```

## Clear a KML layer

Let's assume that you have created this `KmlLayer`:

### Kotlin

```kotlin
val inputStream: InputStream = context.resources.openRawResource(R.raw.kml_file)
val layer = KmlLayer(map, inputStream, context)

      
```

### Java

```java
InputStream inputStream = context.getResources().openRawResource(R.raw.kml_file);
KmlLayer layer = new KmlLayer(map, inputStream, context);

      
```

To remove the layer from the map, call `removeLayerFromMap()`:

### Kotlin

```kotlin
layer.removeLayerFromMap()

      
```

### Java

```java
kmlLayer.removeLayerFromMap();

      
```

## Access KML containers

To access any containers that have been added to your layer,
you can call `getContainers()` on the layer that you have created.
To check if any container has nested containers, you can call
`hasContainers()`. To access these nested containers, similar to
what you are able to do in your layer, you can call
`getContainers()`

To access containers which are *not* nested in a `KmlLayer`
or `KmlContainer:`

### Kotlin

```kotlin
for (container in layer.getContainers()) {
    // Do something to container
}

      
```

### Java

```java
for (KmlContainer containers : layer.getContainers()) {
    // Do something to container
}

      
```

To access containers which *are* nested in a `KmlLayer`
or `KmlContainer`:

### Kotlin

```kotlin
fun accessContainers(containers: Iterable<KmlContainer>) {
    for (container in containers) {
        if (container.hasContainers()) {
            accessContainers(container.getContainers())
        }
    }

      
```

### Java

```java
public void accessContainers(Iterable<KmlContainer> containers) {
    for (KmlContainer container : containers) {
        if (container.hasContainers()) {
            accessContainers(container.getContainers());
        }
    }
}


      
```

## Access KML placemarks and KML ground overlays

To access any placemark or ground overlay that has been
added to the layer, you can call `getPlacemarks()` or
`getGroundOverlays()` on a layer or container. Calling either will
return an iterable of `KmlPlacemarks` or
`KmlGroundOverlays` respectively.

For example, to access a `KmlPlacemark` objects from a layer:

### Kotlin

```kotlin
for (placemark in layer.getPlacemarks()) {
    // Do something to Placemark
}

      
```

### Java

```java
for (KmlPlacemark placemark : layer.getPlacemarks()) {
    // Do something to Placemark
}

      
```

## Access KML properties

To access any property in a container or placemark, call
`getProperty()` and give it a property key. You can also call
`hasProperty()` to check if it exists. This sample shows how to
retrieve the property value "name" from a container, if it exists.

### Kotlin

```kotlin
for (container in layer.getContainers()) {
    if (container.hasProperty("name")) {
        Log.i("KML", container.getProperty("name") ?: "")
    }
}

      
```

### Java

```java
for (KmlContainer container : layer.getContainers()) {
    if (container.hasProperty("name")) {
        Log.i("KML", container.getProperty("name"));
    }
}

      
```

## KML Geometry Click Events

You can use `KmlLayer.OnFeatureClickListener()` to listen for click events on the
geometry features on the map. The following example logs the ID of a feature when the user
clicks the feature:

### Kotlin

```kotlin
// Set a listener for geometry clicked events.
layer.setOnFeatureClickListener { feature ->
    Log.i("KML", "Feature clicked: ${feature.getId()}")
}

      
```

### Java

```java
// Set a listener for geometry clicked events.
layer.setOnFeatureClickListener(
        new KmlLayer.OnFeatureClickListener() {
            @Override
            public void onFeatureClick(Feature feature) {
                Log.i("KML", "Feature clicked: " + feature.getId());
            }
        });

      
```

## See the demo app

For an example of importing a KML file and creating a layer
with it, take a look at the `KmlDemoActivity` in the demo app
that ships with the utility library. The [setup guide](https://developers.google.com/maps/documentation/android-sdk/utility/setup.md.txt) shows you how
to run the demo app.

## KML supported features

| KML Element | Supported? | Comment |
|---|---|---|
| \<address\> | partially | Stored as a property value |
| \<AddressDetails\> | no |   |
| \<Alias\> | no |   |
| \<altitude\> | no |   |
| \<altitudeMode\> | no |   |
| \<atom:author\> | no |   |
| \<atom:link\> | no |   |
| \<atom:name\> | no |   |
| \<BalloonStyle\> | partially | only \<text\> is supported |
| \<begin\> | N/A | \<TimeSpan\> is not supported |
| \<bgColor\> | no |   |
| \<bottomFov\> | N/A | \<PhotoOverlay\> is not supported |
| \<Camera\> | no |   |
| \<Change\> | partially | only style changes are supported |
| \<color\> | partially | includes #AABBGGRR and #BBGGRR; not supported in \<ScreenOverlay\>, and \<GroundOverlay\> |
| \<colorMode\> | yes |   |
| \<cookie\> | no | \<NetworkLinkControl\> not supported |
| \<coordinates\> | yes |   |
| \<Create\> | no |   |
| \<Data\> | no |   |
| \<Delete\> | no |   |
| \<description\> | yes | Plain text only, no HTML content is supported |
| \<displayMode\> | no |   |
| \<displayName\> | no |   |
| \<Document\> | yes |   |
| \<drawOrder\> | yes |   |
| \<east\> | yes |   |
| \<end\> | N/A | \<TimeSpan\> is not supported |
| \<expires\> | no | \<NetworkLinkControl\> not supported |
| \<ExtendedData\> | partially | untyped \<Data\> only, no \<SimpleData\> or \<Schema\>, and entity replacements of the form$\[dataName\] are unsupported. |
| \<extrude\> | no |   |
| \<fill\> | yes |   |
| \<flyToView\> | no | \<NetworkLinkControl\> not supported |
| \<Folder\> | yes |   |
| \<gridOrigin\> | N/A | \<PhotoOverlay\> is not supported |
| \<GroundOverlay\> | yes |   |
| \<heading\> | yes |   |
| \<hotSpot\> | yes |   |
| \<href\> | yes |   |
| \<httpQuery\> | no |   |
| \<Icon\> | yes |   |
| \<IconStyle\> | yes |   |
| \<ImagePyramid\> | N/A | \<PhotoOverlay\> is not supported |
| \<innerBoundaryIs\> | yes | implicitly from \<LinearRing\> order |
| \<ItemIcon\> | N/A | \<ListStyle\> is not supported |
| \<key\> | yes |   |
| \<kml\> | yes |   |
| \<LabelStyle\> | no |   |
| \<latitude\> | yes |   |
| \<LatLonAltBox\> | no |   |
| \<LatLonBox\> | yes |   |
| \<leftFov\> | N/A | \<PhotoOverlay\> is not supported |
| \<LinearRing\> | yes |   |
| \<LineString\> | yes |   |
| \<LineStyle\> | yes |   |
| \<Link\> | no |   |
| \<linkDescription\> | N/A | \<NetworkLinkControl\> not supported |
| \<linkName\> | N/A | \<NetworkLinkControl\> not supported |
| \<linkSnippet\> | N/A | \<NetworkLinkControl\> not supported |
| \<listItemType\> | N/A | \<ListStyle\> is not supported |
| \<ListStyle\> | no |   |
| \<Location\> | N/A | \<Model\> is not supported |
| \<Lod\> | yes |   |
| \<longitude\> | yes |   |
| \<LookAt\> | no |   |
| \<maxAltitude\> | no |   |
| \<maxFadeExtent\> | no |   |
| \<maxHeight\> | N/A | \<PhotoOverlay\> is not supported |
| \<maxLodPixels\> | no |   |
| \<maxSessionLength\> | no |   |
| \<maxWidth\> | N/A | \<PhotoOverlay\> is not supported |
| \<message\> | no |   |
| \<minAltitude\> | no |   |
| \<minFadeExtent\> | no |   |
| \<minLodPixels\> | no |   |
| \<minRefreshPeriod\> | no | \<NetworkLink\> |
| \<Model\> | no |   |
| \<MultiGeometry\> | yes |   |
| \<name\> | yes |   |
| \<near\> | N/A | \<PhotoOverlay\> is not supported |
| \<NetworkLink\> | no |   |
| \<NetworkLinkControl\> | no |   |
| \<north\> | yes |   |
| \<open\> | yes | Stored as a property value |
| \<Orientation\> | N/A | \<Model\> is not supported |
| \<outerBoundaryIs\> | yes | implicitly from \<LinearRing\> order |
| \<outline\> | yes |   |
| \<overlayXY\> | no |   |
| \<Pair\> | yes |   |
| \<phoneNumber\> | partially | Stored as a property value |
| \<PhotoOverlay\> | no |   |
| \<Placemark\> | yes |   |
| \<Point\> | yes |   |
| \<Polygon\> | yes |   |
| \<PolyStyle\> | yes |   |
| \<range\> | yes |   |
| \<refreshInterval\> | no |   |
| \<refreshMode\> | no |   |
| \<refreshVisibility\> | no |   |
| \<Region\> | yes |   |
| \<ResourceMap\> | N/A | \<Model\> is not supported |
| \<rightFov\> | N/A | \<PhotoOverlay\> is not supported |
| \<roll\> | N/A | \<Camera\> and \<Model\> are not supported |
| \<rotation\> | yes |   |
| \<rotationXY\> | no |   |
| \<Scale\> | N/A | \<Model\> is not supported |
| \<scale\> | yes |   |
| \<Schema\> | no |   |
| \<SchemaData\> | no |   |
| \<ScreenOverlay\> | no |   |
| \<screenXY\> | N/A | \<ScreenOverlay\> is not supported |
| \<shape\> | N/A | \<PhotoOverlay\> is not supported |
| \<SimpleData\> | N/A | \<SchemaData\> are not supported |
| \<SimpleField\> | N/A | \<Schema\> are not supported |
| \<size\> | yes |   |
| \<Snippet\> | no |   |
| \<south\> | yes |   |
| \<state\> | N/A | \<ListStyle\> is not supported |
| \<Style\> | yes |   |
| \<StyleMap\> | partially | Highlighted style not supplied. Inline StyleMaps not supported |
| \<styleUrl\> | yes |   |
| \<targetHref\> | no | \<Alias\> is not supported |
| \<tessellate\> | no |   |
| \<text\> | yes |   |
| \<textColor\> | no |   |
| \<tileSize\> | N/A | \<PhotoOverlay\> is not supported |
| \<tilt\> | no |   |
| \<TimeSpan\> | no |   |
| \<TimeStamp\> | no |   |
| \<topFov\> | N/A | \<PhotoOverlay\> is not supported |
| \<Update\> | N/A | \<NetworkLinkControl\< not supported |
| \<value\> | yes |   |
| \<viewBoundScale\> | no |   |
| \<viewFormat\> | no |   |
| \<viewRefreshMode\> | no |   |
| \<viewRefreshTime\> | no |   |
| \<ViewVolume\> | N/A | \<PhotoOverlay\> is not supported |
| \<visibility\> | yes |   |
| \<west\> | yes |   |
| \<when\> | N/A | \<TimeStamp\> is not supported |
| \<width\> | yes |   |