Search code examples
javascripthtmlgoogle-earth-plugin

array of placemark id with google earth api


Anyone know how to get the id of multiple placemarks each one created with the following code:

terrainPlacemark = makePlacemark(hitTestResult.getLatitude(), hitTestResult.getLongitude(),
          hitTestResult.getAltitude(), ge.ALTITUDE_ABSOLUTE, 'T'); 

//set placemark name
terrainPlacemark.setName("placemark" + counter);

//set the placemark on the map
ge.getFeatures().appendChild(terrainPlacemark);

function makePlacemark(lat, lng, alt, altMode, iconStr) {
      var icon = ge.createIcon('');
      icon.setHref('http://maps.google.com/mapfiles/kml/paddle/' + iconStr + '.png');

      var style = ge.createStyle('');
      style.getIconStyle().setIcon(icon);
      style.getIconStyle().getHotSpot().set(0.5, ge.UNITS_FRACTION, 0, ge.UNITS_FRACTION);

      var pt = ge.createPoint('');
      pt.set(lat, lng, alt, altMode, false, false);

      var pm = ge.createPlacemark('');
      pm.setGeometry(pt);
      pm.setStyleSelector(style);

      return pm;
}

They are created on a click of google earth api.


Solution

  • They don't have an ID, because you explicitly did not set one by passing in an empty string to the createPlacemark method

    Instead, try ge.createPlacemark('anyUniqueID')