Cutting Edge > Enhance Your Teaching > Teaching Methods > Teaching with Google Earth > How to Teach With Google Earth > Working with KML

Working with KML

Looking at KML

To see the KML code that defines a feature or container in Google Earth, right-click it in the Places Pane. Choose Copy, then paste it into a text editor. The following is the complete KML code for a file that defines a simple placemark. The first two lines and the last one are needed to identify the contents of the file as KML markup. Note that the markup consists of paired tags that enclose information. The opening tag for each pair is identical to the closing tag, except that the closing tag includes a forward slash after the opening angle bracket. The opening and closing tags along with the content they enclose comprise an element. In many cases, elements contain additional elements. After defining some style information, this example defines a placemark, beginning with an opening member of a the Placemark tag pair. Note that the tag names are case-sensitive.

The name element within the Placemark element specifies the name that will appear in the Places Pane and next to the placemark's icon in the 3D Viewer. The description is what appears in its information balloon. The LookAt element specifies the view that occurs when the placemark is opened in Google Earth or double-clicked in the Places Pane. The styleUrl element refers to a style that is defined in the beginning portion of the file. The Point element contains coordinates as longitude, latitude, and altitude in that order. The longitude and latitude are in decimal degrees and the altitude is in meters. Unless specified as otherwise, it is relative to the ground.

A Simple Placemark

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
  <name>KmlFile</name>
  <StyleMap id="msn_ylw-pushpin">
    <Pair>
      <key>normal</key>
      <styleUrl>#sn_ylw-pushpin</styleUrl>
    </Pair>
    <Pair>
      <key>highlight</key>
      <styleUrl>#sh_ylw-pushpin</styleUrl>
    </Pair>
  </StyleMap>
  <Style id="sh_ylw-pushpin">
    <IconStyle>
      <scale>1.3</scale>
      <Icon>
        <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
      </Icon>
      <hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/>
    </IconStyle>
  </Style>
  <Style id="sn_ylw-pushpin">
    <IconStyle>
      <scale>1.1</scale>
      <Icon>
        <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
      </Icon>
      <hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/>
    </IconStyle>
  </Style>
  <Placemark>
    <name>Mussels on Jetty</name>
    <description>Blue mussels on a jetty at Flax Pond</description>
    <LookAt>
      <longitude>-73.13725182375889</longitude>
      <latitude>40.96604827163384</latitude>
      <altitude>0</altitude>
      <range>122.7175412528925</range>
      <tilt>0</tilt>
      <heading>0.4722662207524233</heading>
      <altitudeMode>relativeToGround</altitudeMode>
    </LookAt>
    <styleUrl>#msn_ylw-pushpin</styleUrl>
    <Point>
      <coordinates>-73.1372092222108,40.96604056835132,0</coordinates>
    </Point>
  </Placemark>
</Document>
</kml>

A Placemark with a Flickr Photo in the Description

The example below uses a photograph from the Flax Pond Identification Guide, which is a collection of geotagged photographs of plants and environments in a salt marsh. The description tag for this placemark contains HTML that embeds a photograph that resides on Flickr into the information balloon. The img tag that references the photograph is surrounded by an a href tag that causes the photograph to link to its photo page on the Flickr server when it is clicked in the information bubble.

Flax Pond Placemark Balloon

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
  <name>KmlFile</name>
  <Style id="sh_ylw-pushpin">
    <IconStyle>
      <scale>1.3</scale>
      <Icon>
        <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
      </Icon>
      <hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/>
    </IconStyle>
  </Style>
  <StyleMap id="msn_ylw-pushpin">
    <Pair>
      <key>normal</key>
      <styleUrl>#sn_ylw-pushpin</styleUrl>
    </Pair>
    <Pair>
      <key>highlight</key>
      <styleUrl>#sh_ylw-pushpin</styleUrl>
    </Pair>
  </StyleMap>
  <Style id="sn_ylw-pushpin">
    <IconStyle>
      <scale>1.1</scale>
      <Icon>
        <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
      </Icon>
      <hotSpot x="20" y="2" xunits="pixels" yunits="pixels"/>
    </IconStyle>
  </Style>
  <Placemark>
    <name>Tidal Marsh Zonation</name>
    <description><![CDATA[<a href="http://www.flickr.com/photos/9428166@N03/2686452579/in/set-72157606317334698/"><img src="http://farm4.static.flickr.com/3180/2686452579_e45ef2cab0.jpg"></a>
</br>In the foreground is high marsh composed mostly of Spartina patens. Behind the high marsh area, Spartina alterniflora (low marsh) becomes increasingly dominant.
</br>]]></description> <LookAt> <longitude>-73.13937247683684</longitude> <latitude>40.96455409672829</latitude> <altitude>0</altitude> <range>784.62675278833</range> <tilt>0</tilt> <heading>0.4708758714693997</heading> </LookAt> <styleUrl>#msn_ylw-pushpin</styleUrl> <Point> <coordinates>-73.1447,40.9634,0</coordinates> </Point> </Placemark> </Document> </kml>

Proceed to KML Examples from the Google Earth Community Forums.

Or for additional information about using KML, see Google: What is KML?


« Previous Page      Next Page »