Google Earth API Samples - Parse KML (Interactive)

Last Modified:
08/04/08

Parse this KML:


Relevant Code Excerpt:

var currentKmlObject = null;

function parseKmlFromTextarea() {
  // remove the old parsed KML object if one exists
  if (currentKmlObject)
    ge.getFeatures().removeChild(currentKmlObject);

  var kmlBox = document.getElementById('kml-box');
  var kmlString = kmlBox.value;

  // parse the text in the box and add it to Earth
  try {
    currentKmlObject = ge.parseKml(kmlString);
    ge.getFeatures().appendChild(currentKmlObject);
  } catch (ex) {
    alert('Parse error');
  }
}