1. getUrl()
  2. getComputedStyle()
  3. getElementByUrl()
  4. getElementById()
  5. getElementsByType()


An object's URL is its base address concatenated with its ID using the # character. This URL can be returned by calling getUrl() on the object.

var placemarkUrl = placemark.getUrl();

Objects created with the API (rather than imported as KML) do not have a base address; their URL will consist of a # character and their ID.


Returns the object's style properties as a KMLStyle object, merging any inline styles with styles imported from setHref() or a StyleUrl.

var placemark = ge.createPlacemark('');

var icon = ge.createIcon('');
var style = ge.createStyle('');

var placemarkStyle = placemark.getComputedStyle();

alert('Icon color: '
      + placemarkStyle.getIconStyle().getColor().get()
      + '\n'
      + 'Icon scale: '
      + placemarkStyle.getIconStyle().getScale());


Objects that are imported as KML have an identifying URL consisting of their base address and ID, joined with the # character. For example, if http://code.google.com/foo.kml is fetched and contains the following:

    <Placemark id='elvis_was_here'>

The placemark can be retrieved with:

var pm = ge.getElementByUrl('http://code.google.com/foo.kml#elvis_was_here');

If the object was created with the API, it can be retrieved by including only the hash and the object's ID:


Alternatively, API-created objects can be returned using getElementById().


When an object is created with the API, rather than imported as KML, the object does not have a base address. In this case, the object can be returned by passing only its ID to getElementById().

var overlay = ge.createPhotoOverlay('graceland_panorama');
var myPhotoOverlay = ge.getElementById('graceland_panorama');


You can obtain an array of all elements of a certain type, by passing that type as a string to getElementsByType().

var placemarks = ge.getElementsByType('KmlPlacemark');
for (var i = 0; i < placemarks.getLength(); ++i) {
  var placemark = placemarks.item(i);

This method can also be called on any KMLFeature object, such as a folder, to return only objects within that specific container.

For a list of valid types, refer to the API Reference. You can also call getType() on any existing object to return its type as a string.


Send feedback about...

Google Earth API (Deprecated)