Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8497861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:14:45+00:00 2026-06-11T00:14:45+00:00

I’m experimenting with the Google Earth Plugin API for an application that I’m writing.

  • 0

I’m experimenting with the Google Earth Plugin API for an application that I’m writing. I want to be able to delete placemarks from the map. The simplest way I could think of to do this is to create a balloon popup with a ‘Delete’ link but I’ve been unable to figure out how to do delete:

balloon.setContentString(
'Location: ' + event.getLatitude().toString() + ", " +
event.getLongitude().toString() + '<br />&nbsp;<br />' +
'<a href="#" onclick="ge.getFeatures().removeChild(event.getCurrentTarget())">Delete</a><br /><a href="#" onclick="prompt(\'Enter new name\', \'blah\'\)">Rename</a>');

This results in:

Uncaught TypeError: Object #<MouseEvent> has no method 'getCurrentTarget' earth2.html:1 onclick

(As you can see I also want to be able to rename, but presumably that won’t be so hard to figure out when I’ve figured out deleting?)

The entire code can be found at:

http://chrishowells.co.uk:81/earth2.html

The entire block:

google.earth.addEventListener(ge.getWindow(), 'mousedown', function(event) {
if (event.getTarget().getType() == 'KmlPlacemark' &&
    event.getTarget().getGeometry().getType() == 'KmlPoint') {
  // don't show the default popup
  //http://code.google.com/apis/ajax/playground/?exp=earth#javascript_in_balloons
  event.preventDefault();

var balloon = ge.createHtmlStringBalloon('');
balloon.setFeature(event.getTarget());
//balloon.setMaxWidth(300);

balloon.setContentString(
  'Location: ' + event.getLatitude().toString() + ", " +
event.getLongitude().toString() + '<br />&nbsp;<br />' +
'<a href="#" onclick="ge.getFeatures().removeChild(event.getCurrentTarget())">Delete</a><br /><a href="#" onclick="prompt(\'Enter new name\', \'blah\'\)">Rename</a>');
ge.setBalloon(balloon);

var placemark = event.getTarget();

dragInfo = {
    placemark: event.getTarget(),
    dragged: false
  };
}
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:14:47+00:00Added an answer on June 11, 2026 at 12:14 am

    The error you are getting is telling you exactly what the problem is.

     Object #<MouseEvent> has no method 'getCurrentTarget'
    

    The issue being that within the onclick event handler of the anchor the event variable referrers to the click on the link rather than the click on the placemark. That is the event is a DOM mouse event rather than a KmlMouseEvent.

    Also, the method you need to call to reference the object to which the KMLEvent was originally dispatched is getTarget.

    See the API guide for KmlEvent.getTarget:
    https://developers.google.com/earth/documentation/reference/interface_kml_event#adfee4d0797ff7d437e77c649673f9ffc

    To fix this you need to do a number of things, firstly define a global variable to hold any current placemark click event. Do this at the top of the script where you define the ge variable add a currentEvent variable as well. i.e.

    var ge = null; 
    var currentEvent = null;
    

    Secondly your mousedown listener should be ammended to allow the javascript in the balloon to reference the currentEvent variable you have defined.

    Finally, you should then use the currentEvent variable to reference the Placemark to remove it via the code in the balloon.

    For example.

    google.earth.addEventListener(ge.getWindow(), 'mousedown', function(event) {
    
        if (event.getTarget().getType() == 'KmlPlacemark' &&
        event.getTarget().getGeometry().getType() == 'KmlPoint') {
            currentEvent = event; // used in the balloon content string
            event.preventDefault();
    
            var balloon = ge.createHtmlStringBalloon('');
            balloon.setFeature(event.getTarget());
    
            balloon.setContentString(
            'Location: ' + event.getLatitude().toString() + ", " +
            event.getLongitude().toString() + '<br />&nbsp;<br />' +
            '<a href="#" onclick="ge.getFeatures().removeChild(currentEvent.getTarget());ge.setBalloon(null);">Delete</a><br /><a href="#" onclick="prompt(\'Enter new name\', \'blah\'\)">Rename</a>');
            ge.setBalloon(balloon);
    
            dragInfo = {
                placemark: event.getTarget(),
                dragged: false
            };
        }
    });
    

    I have tested this fully and it works AOK, when you click delete the placemark is removed and the current balloon is closed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.