Search code examples
kmlgoogle-earth

How does a KML file help in loading maps in the Google Earth?


https://developers.google.com/kml/documentation/kml_tut

KML uses a tag-based structure with nested elements and attributes and is based on the XML standard.

So, KML is basically a "text" file, it doesn't contain the maps.

How does Google Earth use KML files to show maps? Does it treat KML file as an "index" to know which of its maps to pick when user presses x button?


Solution

  • KML is an XML language used to annotate the Earth with points, lines, polygons, 3d models, and overlays.

    As an analogy, HTML is a language to structure and represent textual information and multi-media in a 2-D document context within a web browser. Likewise, KML is a language to structure and represent geospatial and temporal entities on a map and show in "earth browsers" such as Google Earth.

    Specifically KML allows you to :

    • Specify icons and labels to identify locations on the surface of the planet
    • Create different camera positions to define unique views for geographic features
    • Define image overlays to attach to ground or screen
    • Define styles to specify KML feature appearance
    • Organize KML features into hierarchies
    • Locate and update retrieved KML documents from local or remote network locations

    KML is a structured format of data that tells Google Earth how to display the data (point, line, icons, colors, styles, etc.) and where to draw it (longitude and latitude optionally at a given altitude). KML is simply a data exchange format.

    Here's a simple KML file:

    <?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://www.opengis.net/kml/2.2">
    <Document>
    <Placemark>
      <name>New York City</name>
      <description>New York City</description>
      <Point>
        <coordinates>-74.006393,40.714172</coordinates>
      </Point>
    </Placemark>
    </Document>
    </kml>
    

    As an "index", a KML file by default will load at the center point that covers all includes features in the KML, but that can be overridden if a LookAt or Camera is defined. If you click on a Placemark it will fly to that feature as defined by its coordinates.

    Clicking on such a placemark in Google Earth will fly to that location, which for the example above happens to be New York City.

    KML is a "text" file that can also be packaged and distributed in a "KMZ" file, which is a ZIP file with .kmz file extension.

    More details about KML can be in the OGC KML Standard # 07-147r2 .