What is a KML file?
KML (Keyhole Markup Language) is an XML-based format for expressing geographic annotations and visualizations in 2D maps and 3D Earth browsers. It was originally developed by Keyhole Inc. (acquired by Google in 2004) for Google Earth, and became an Open Geospatial Consortium (OGC) international standard in 2008. KML goes beyond raw coordinate storage (like GPX) — it includes rich styling, 3D geometry, camera viewpoints, time-based animations, and embedded media.
The “Keyhole” name refers to the Cold War-era KH (Keyhole) reconnaissance satellite program, a nod to the bird’s-eye-view perspective of the software.
How to open KML files
- Google Earth (Windows, macOS, Linux, Web) — The native format; full feature support including 3D and time animation
- Google Maps (Web) — Import KML for basic visualization (limited feature support)
- QGIS (Windows, macOS, Linux) — Free professional GIS with full KML import
- ArcGIS (Windows) — Professional GIS platform
- Mapbox / Leaflet — JavaScript mapping libraries can render KML via plugins
- Any text editor — KML is human-readable XML
Technical specifications
| Property | Value |
|---|---|
| Format | XML |
| OGC Standard | OGC KML 2.3 |
| Coordinate order | Longitude, latitude, altitude (note: reversed from GPX) |
| Features | Placemarks, paths, polygons, overlays, 3D models, camera tours |
| Styling | Inline <Style> elements with colors, icons, line widths |
| Compressed variant | KMZ (ZIP archive containing KML + embedded resources) |
KML file structure
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>FileDex Locations</name>
<!-- Styled placemark -->
<Style id="redIcon">
<IconStyle>
<color>ff0000ff</color>
<scale>1.2</scale>
</IconStyle>
</Style>
<Placemark>
<name>London</name>
<styleUrl>#redIcon</styleUrl>
<Point>
<coordinates>-0.1278,51.5074,0</coordinates>
</Point>
</Placemark>
<!-- Polygon (area boundary) -->
<Placemark>
<name>City Area</name>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
-0.13,51.51,0 -0.12,51.51,0
-0.12,51.50,0 -0.13,51.50,0
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Document>
</kml>
KML vs GPX
| Feature | KML | GPX |
|---|---|---|
| Primary use | Visualization and presentation | GPS data exchange |
| Styling | ✅ Rich (colors, icons, labels) | ❌ No native styling |
| 3D geometry | ✅ Supported | ❌ |
| Camera tours | ✅ | ❌ |
| Time animation | ✅ <TimeSpan>, <TimeStamp> | ❌ |
| Fitness data | ❌ | ✅ (HR, cadence, power) |
| OGC standard | ✅ | ✅ (de facto) |
KML is better for rich map presentations; GPX is better for fitness and navigation data exchange.
Common use cases
- Google Earth presentations: Interactive geographic tours with camera paths, overlays, and time animation
- Real estate: Property boundary visualization, development area overlays
- Environmental science: Habitat mapping, deforestation tracking, flood zone visualization
- Urban planning: City zoning maps, infrastructure planning, transit route visualization
- Data journalism: Interactive maps embedded in news articles via Google My Maps
- Emergency management: Evacuation zones, disaster impact areas
KMZ — the compressed variant
KMZ files are ZIP archives containing a doc.kml root file plus any referenced resources (images, 3D models, icons). Use KMZ to distribute self-contained maps with all embedded imagery. Google Earth opens KMZ files directly. To inspect contents, rename .kmz to .zip and extract normally.
Converting KML to other formats
- GDAL/OGR:
ogr2ogr -f GeoJSON output.geojson input.kml - GPSBabel: Convert between KML and GPX
- mapshaper: Web tool for converting and simplifying geographic data
- Overpass Turbo: Export OpenStreetMap data as KML