I want to do something similar like this but with the Google Earth API. Is there any way to use it with the Google Earth API? Can I add placemark by click on the earth map?
0
votes
1 Answers
0
votes
Here's sample code to create a new Placemark at the place you click on the map with an event listener on the map using Google Earth API.
function init() {
google.earth.createInstance('map3d', initCallback, failureCallback);
}
function initCallback(instance) {
ge = instance;
ge.getWindow().setVisibility(true);
google.earth.addEventListener(ge.getGlobe(), 'click', eventHandler);
}
function eventHandler(event) {
var placemark = ge.createPlacemark('');
placemark.setName("placemark");
var point = ge.createPoint('');
point.setLatitude(event.getLatitude());
point.setLongitude(event.getLongitude());
placemark.setGeometry(point);
ge.getFeatures().appendChild(placemark);
}
Click here for details to add an event listener to the globe and respond to events in GE API. Note that the click and dbclick events are normally used by Google Earth plugin for navigation so you may want a button to toggle the click listener on/off. Here's an example to toggle event listeners.
Remember you have to add a listener after you have an instance of the Google Earth plugin controller.