KML file format

A KML file is a text file that describes what to show on a map or a globe, such as places, lines and areas, with their colours and icons. It was made for Google Earth and is now an open standard of the Open Geospatial Consortium (OGC).

Full name
Keyhole Markup Language
Extension
.kml
Type
XML text
Standard
OGC KML 2.2
Zipped version
KMZ

Open a KML file in the KML viewer. It runs in your browser, and the file never leaves your device.

What a KML file can store

DataKML
Recorded tracksYes
More than one trackYes
Track segmentsYesAs a MultiGeometry
Planned routesYesWritten as lines, read back as tracks
WaypointsYesAs Point placemarks
File name and titleYes
DescriptionYes
AuthorNo
Creation timeNo
LinksNo
Track namesYes
Activity typeNo
ElevationYes
TimestampsYesOnly in gx:Track
Heart rateWith an extensionExtendedData in gx:Track
CadenceWith an extensionExtendedData in gx:Track
PowerWith an extensionExtendedData in gx:Track
TemperatureWith an extensionExtendedData in gx:Track
SpeedWith an extensionExtendedData in gx:Track

This table comes from the code of TrackLoupe, and the notes say how each field is stored. The converters use the same table to tell you what a conversion keeps and what it loses.

What is inside a KML file

A KML file is XML. Its content sits in a <Document>, often organised in <Folder> elements. Each item on the map is a <Placemark> with a name, a description and a geometry:

Styles (<Style>) set the colours, the line widths and the icons.

Coordinates come in the order longitude, latitude, altitude, separated by commas, with a space between points. Most people expect latitude first, so a file written in the wrong order puts its points in another part of the world. Altitude is optional and in metres.

This is a short KML file with a placemark for the start and a line:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <name>Morning ride</name>
    <Placemark>
      <name>Start</name>
      <Point>
        <coordinates>-9.1394,38.7139,45</coordinates>
      </Point>
    </Placemark>
    <Placemark>
      <name>Morning ride</name>
      <LineString>
        <coordinates>-9.1394,38.7139,45 -9.1388,38.7142,46 -9.1381,38.7146,47</coordinates>
      </LineString>
    </Placemark>
  </Document>
</kml>

Times and sensor data in gx:Track

A <LineString> has no times. Google added its own element for recorded tracks, <gx:Track>. It pairs each position (<gx:coord>, with the three values separated by spaces) with a time (<when>). Sensor values such as heart rate or cadence can follow in <ExtendedData>, with one value per point, and Google Earth shows them in the elevation profile of the track.

TrackLoupe reads gx:Track with its times. It recognises heart rate, cadence, power, temperature and speed in the extended data by their names.

How TrackLoupe reads a KML file

How to open a KML file

Questions

What is a KML file used for?

It shows places, routes and areas on a map or a globe. Google Earth is the best known program that uses it, and the OGC standard makes it common in mapping software.

What is the difference between KML and KMZ?

A KMZ file is a KML file compressed in a ZIP archive, often with its icons and images. The KML vs KMZ page explains when to use each.

Can I convert a KML file to GPX here?

Not yet. A KML to GPX converter is listed under “Coming next” on the tools page. Until then, the KML viewer shows what the file holds.

Why are my KML points in the wrong place?

The coordinates may be in the wrong order. KML puts longitude first. A file written with latitude first moves every point, often into the sea or onto another continent.

Why does my KML file show nothing in the viewer?

The file may hold only polygons or a network link, which the viewer leaves out. The note above the drawing says what it skipped.