First of all, what is KML?. KML is a file format used to display geographic data in an Earth browser, such as Google Earth, Google Maps, and Google Maps for mobile. You can create KML files to pinpoint locations, add image overlays, and expose rich data in new ways. KML is an international standard maintained by the Open Geospatial Consortium, Inc. (OGC). You can choose wether authoring directly from Google Earth itself or you can try to understand the code and doing it by yourself… You can draw placemarks (using descriptive HTML to personalize them), ground overlays, paths, polygons… Let’s start with the placemark:
-> Simple placemark
<?xml version=”1.0″ encoding=”UTF-8″?>
<kml xmlns=”http://www.opengis.net/kml/2.2″>
<Placemark>
<name>Simple placemark</name>
<description>Attached to the ground. Intelligently places itself
at the height of the underlying terrain.</description>
<Point>
<coordinates>-122.0822035425683,37.42228990140251,0</coordinates>
</Point>
</Placemark>
</kml>
- A name that is used as the label for the Placemark
- A description that appears in the “balloon” attached to the Placemark
- A Point that specifies the position of the Placemark on the Earth’s surface (longitude, latitude, and optional altitude)
-> Floating placemark
<?xml version=”1.0″ encoding=”UTF-8″?>
<kml xmlns=”http://www.opengis.net/kml/2.2” xmlns:gx=”http://www.google.com/kml/ext/2.2” xmlns:kml=”http://www.opengis.net/kml/2.2” xmlns:atom=”http://www.w3.org/2005/Atom“>
<Document>
<name>Floating placemark.kml</name>
<Style id=”downArrowIcon”>
<IconStyle>
<Icon>
<href>http://maps.google.com/mapfiles/kml/pal4/icon28.png</href>
</Icon>
</IconStyle>
</Style>
<Placemark>
<name>Floating placemark</name>
<description>Floats a defined distance above the ground.</description>
<LookAt>
<longitude>-122.0839597145766</longitude>
<latitude>37.42222904525232</latitude>
<altitude>0</altitude>
<range>500.6566641072245</range>
<tilt>40.5575073395506</tilt>
<heading>-148.4122922628044</heading>
</LookAt>
<styleUrl>#downArrowIcon</styleUrl>
<Point>
<altitudeMode>relativeToGround</altitudeMode>
<coordinates>-122.084075,37.4220033612141,50</coordinates>
</Point>
</Placemark>
</Document>
</kml>
-> Extruded placemark
<?xml version=”1.0″ encoding=”UTF-8″?>
<kml xmlns=”http://www.opengis.net/kml/2.2” xmlns:gx=”http://www.google.com/kml/ext/2.2” xmlns:kml=”http://www.opengis.net/kml/2.2” xmlns:atom=”http://www.w3.org/2005/Atom“>
<Document>
<name>Extruded placemark.kml</name>
<Style id=”globeIcon”>
<IconStyle>
<Icon>
<href>http://maps.google.com/mapfiles/kml/pal3/icon19.png</href>
</Icon>
</IconStyle>
<LineStyle>
<width>2</width>
</LineStyle>
</Style>
<Placemark>
<name>Extruded placemark</name>
<description>Tethered to the ground by a customizable
"tail"</description>
<LookAt>
<longitude>-122.0845787421525</longitude>
<latitude>37.42215078737763</latitude>
<altitude>0</altitude>
<range>365.2646606980322</range>
<tilt>40.55750733918048</tilt>
<heading>-148.4126684946234</heading>
</LookAt>
<styleUrl>#globeIcon</styleUrl>
<Point>
<extrude>1</extrude>
<altitudeMode>relativeToGround</altitudeMode>
<coordinates>-122.0857667006183,37.42156927867553,50</coordinates>
</Point>
</Placemark>
</Document>
</kml>
If instead of regular <description>
<description>Attached to the ground. Intelligently places itself
at the height of the underlying terrain.</description>
you use the CDATA element, you can write HTML and avoiding Google Earth from parsing the code incorrectly:
<description>
<![CDATA[
<h1>CDATA Tags are useful!</h1>
<p><font color=”red”>Text is <i>more readable</i> and
<b>easier to write</b> when you can avoid using entity
references.</font></p>
]]>
</description>