Search notes:

Google Earth: kml examples

Some examples for Keyhole Markup Language (KML).

A simple placemark

A simple placemark that shows the location of a latitude/longitude coordinate pair can be shown with the <Point> element:
The scene was created with the following kml file:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">

  <Placemark>

    <name>A simple placemark on the ground</name>

    <Point>
			<coordinates>8.542952335953721,47.36685263064198,0</coordinates>
    </Point>

  </Placemark>

</kml>
Github repository about-GoogleEarth, path: /kml/placemark-simple.kml

Adding an HTML description

Placemarks can be annotated with HTML:
The scene was created with:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">

  <Placemark>

    <name>Description with html</name>

    <description><![CDATA[

      <h1>HTML is possible within a description</h1>

      Some <span style='color:red'>red text</span>.
      
      <table border=1>
        <tr><td>one  </td><td>foo</td></tr>
        <tr><td>two  </td><td>bar</td></tr>
        <tr><td>three</td><td>baz</td></tr>
      </table>


    ]]></description>

    <Point>
			<coordinates>8.542952335953721,47.36685263064198,0</coordinates>
    </Point>

  </Placemark>

</kml>
Github repository about-GoogleEarth, path: /kml/description-html.kml

Overlaying the ground with images

The ground can be overlayed with images:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">

  <GroundOverlay>

    <name>What does the png say?</name>

    <Icon>
      <href>the_png_says.png</href>
    </Icon>

  	<LatLonBox>
  		<north>46.77980155828784</north>
  		<south>46.65804355828784</south>

  		<east>9.144871415151389</east>
  		<west>8.433995415151397</west>

  		<rotation>30</rotation>
  	</LatLonBox>


  </GroundOverlay>

</kml>
Github repository about-GoogleEarth, path: /kml/GroundOverlay.kml

Screen overlay

Similarly, the screen can be overlaid with an image. The image does not move with the Earth:
<?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">

  <ScreenOverlay>


    <!-- Origin (x=0/y=0) is in the lower left corner.

         y goes up, x goes right.

      -->

<!-- Place the upper left corner (0/1) of the image... -->
     <overlayXY  x="0.0" y="1.0" xunits="fraction" yunits="fraction" />

<!-- 10% to the right and 10% from the top of the screen (0.1/0.9) -->
     <screenXY   x="0.1" y="0.9" xunits="fraction" yunits="fraction" />

     <rotationXY x="0.1" y="0.9" xunits="fraction" yunits="fraction" />
     <rotation>10</rotation>

     <size       x="0"   y="0"   xunits="fraction" yunits="fraction" />

     <Icon><href>the_png_says.png</href></Icon>
  
  </ScreenOverlay>

</kml>
Github repository about-GoogleEarth, path: /kml/ScreenOverlay.kml

An extruded placemark

A placemark hovering above a certain place. The line shows above which:
The scene was created with the following kml file:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">

  <Placemark>

    <name>An extruded placemark</name>

    <Point>
			<extrude>1</extrude>
			<altitudeMode>relativeToGround</altitudeMode>
			<coordinates>8.542952335953721,47.36685263064198,200</coordinates>
    </Point>

  </Placemark>

</kml>
Github repository about-GoogleEarth, path: /kml/placemark-extruded.kml

Floating placemark

Floating placemarks are possible:
The scence was created with the following kml file:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">

  <Placemark>

    <name>A floating placemark</name>

    <Point>
			<altitudeMode>relativeToGround</altitudeMode>
			<coordinates>8.542952335953721,47.36685263064198,200</coordinates>
    </Point>

  </Placemark>

</kml>
Github repository about-GoogleEarth, path: /kml/placemark-floating.kml
BTW, the animated gif was produced with Peek.

Cube

The image was produced with the following kml file:
<?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">

  <name>Cube</name>


  <Placemark>


    <Polygon>

      <extrude>1</extrude>

      <altitudeMode>relativeToGround</altitudeMode>

      <outerBoundaryIs>

				<LinearRing>
					<coordinates>
						8.542634850324216,47.36654315613557,100 
            8.54263475978412,47.36550030198994,100 
            8.544161875287033,47.36550183316037,100
            8.54416186368919,47.36654140446431,100
            8.542634850324216,47.36654315613557,100
					</coordinates>
				</LinearRing>

      </outerBoundaryIs>

    </Polygon>

   <!-- - - - - - - - - - - - - - - - - - - - - - - -->

	  <LookAt>
	  	<longitude> 8.543151875920312 </longitude>
	  	<latitude>  47.36561202482072 </latitude>
	  	<altitude>  0                 </altitude>
	  	<heading>   45                </heading>
	  	<tilt>      64                </tilt>
	  	<range>     843               </range>

	  	<gx:altitudeMode>relativeToSeaFloor</gx:altitudeMode>
	  </LookAt>

  </Placemark>


</kml>
Github repository about-GoogleEarth, path: /kml/cube.kml

Polygon

<?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>polygon.kml</name>

	<Style id="orange-5px">
		<LineStyle>
			<color>ff00aaff</color>
			<width>5</width>
		</LineStyle>
	</Style>


	<Placemark>

		<name>A polygon</name>
		<styleUrl>#orange-5px</styleUrl>

		<LineString>

			<tessellate>1</tessellate>
			<coordinates>
        8.542123809233731,47.36651432591258,0
        8.542020373307826,47.36684332453151,0
        8.544057950790664,47.36717881947375,0
        8.544133279150493,47.36684482636069,0
        8.542123809233731,47.36651432591258,0  <!-- End coordinates == start coordinates -->
			</coordinates>

		</LineString>

	</Placemark>

</Document>
</kml>
Github repository about-GoogleEarth, path: /kml/polygon.kml

Folders

<?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>Folders</name>


  <Folder><name>Folder one</name><open>1</open>

	   <Folder><name>subfolder</name><open>1</open>

	   	<Placemark>
	   		<name>Path in subfolder</name>
	   		<styleUrl>#orange-5px</styleUrl>
	   		<LineString>
	   			<tessellate>1</tessellate>
	   			<coordinates>
	   				8.541785133887323,47.36677970505284,0 8.544153942262056,47.36714394255758,0 
	   			</coordinates>
	   		</LineString>
	   	</Placemark>

	   </Folder>

	   <Placemark>
	   	<name>Path in folder one</name>
	   	<styleUrl>#orange-5px</styleUrl>

	   	<LineString>
	   		<tessellate>1</tessellate>
	   		<coordinates>
	   			8.54184232399809,47.36647498852937,0 8.544170241436506,47.36685501672338,0 
	   		</coordinates>
	   	</LineString>

	   </Placemark>

  </Folder>

  <Folder><name>Folder two</name><open>1</open>
  
  	<Placemark><name>Polygon in 2nd folder</name>

  		<styleUrl>#orange-5px</styleUrl>
  		<LineString>
  			<tessellate>1</tessellate>
  			<coordinates>
  				8.541967280275596,47.36615976289033,0 8.544304513152113,47.36655716364855,0 
  			</coordinates>
  		</LineString>
  	</Placemark>
  
  </Folder>

	<Style id="orange-5px">
		<LineStyle>
			<color>ff00aaff</color>
			<width>5</width>
		</LineStyle>
	</Style>

</Document>
</kml>
Github repository about-GoogleEarth, path: /kml/folders.kml

See also

ISO 6709 specifies the coordinates to be in order latitude longitude, yet KML has it in reverse order: first longitude, then latitude.
<Point>, <Polygon>, <Style>
Remove the annoying directions from the Balloons of <Point> elements.
Google Earth
https://github.com/ReneNyffenegger/about-GoogleEarth/tree/master/kml
https://github.com/googlemaps/kml-samples: A repository which is not currently maintained and is kept for historical purpose only.
geodata

Index