A KML (Keyhole Markup Language) file is a plain-text XML format that stores geographic data for visualization in Earth browsers such as Google Earth.
It combines geometry, styling, and metadata into a single file, letting anyone share interactive maps, 3D models, and richly annotated place marks without proprietary software.
Core Structure of a KML Document
Root Element and XML Declaration
Every valid KML file begins with an XML declaration and a single
Without this namespace, Google Earth will refuse to parse the file, so include the full URI: xmlns=”http://www.opengis.net/kml/2.2″.
Document and Folder Hierarchy
The
Inside it,
Each folder can carry a name, description, and visibility flag, giving users immediate context before they expand it.
Placemarks, Points, and Basic Geometry
A
Its child
Remember the order: longitude comes first, then latitude, opposite to the everyday “lat, lon” convention.
Advanced Geometries and Multi-Geometry Tricks
For polygons, use
Styling: Colors, Icons, and Balloon Templates
Shared Styles vs. Inline Styles
Define