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

  • SEARCH
  • Home
  • 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 358883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:20:29+00:00 2026-05-12T12:20:29+00:00

After some advice on how to clear markers on googlemaps, I have a map

  • 0

After some advice on how to clear markers on googlemaps, I have a map which I would like to have only one marker showing (basically the last marker clicked). I would like the user to be able to change thier mind and click multiple times, but not have confusing map of previous clicks etc.

I have tried the map.clearOverlay(); function, but it seems to permantly clear the whole map.

function initialize() {

    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("googlemap"));

        map.setCenter(new GLatLng(50.401515,-4.866943), 8);

        GEvent.addListener(map,"click", function(overlay,latlng) {     
            if (latlng) {   
                var myHtml = "" + latlng ;
                split=myHtml.indexOf(",");       
                x=Math.round(myHtml.slice(1,split)*1000000)/1000000;
                y=Math.round(myHtml.slice(split+1,myHtml.length-1)*1000000)/1000000;
                document.collector.latitude.value=x;
                document.collector.longitude.value=y;
                lat="<br />Latitude: " + x;
                lon="<br />Longitude: " + y;
                latlon=""+lat+lon;

                //map.openInfoWindow(latlng, latlon);
                map.clearOverlay();
                map.addOverlay(new GMarker(latlng));
            }
        });
        map.addControl(new GLargeMapControl3D());
        map.addControl(new GMapTypeControl());
    }
}
  • 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-05-12T12:20:30+00:00Added an answer on May 12, 2026 at 12:20 pm

    Untested, but should do what you want – note that the setLatLng method of GMarker was introduced in API version 2.88:

    function initialize() {
    
        if (GBrowserIsCompatible()) {
            var marker;
    
            function showNewMarker(latlng) {
                marker = new GMarker(latlng);
                map.addOverlay(marker);
                showMarker = updateExistingMarker;
            }
    
            function updateExistingMarker(latlng) {
                marker.setLatLng(latlng);
            }
    
            var showMarker = showNewMarker;
    
            var map = new GMap2(document.getElementById("googlemap"));
    
            map.setCenter(new GLatLng(50.401515,-4.866943), 8);
    
            GEvent.addListener(map,"click", function(overlay,latlng) {     
                if (latlng) {   
                    var myHtml = "" + latlng ;
                    split=myHtml.indexOf(",");       
                    x=Math.round(myHtml.slice(1,split)*1000000)/1000000;
                    y=Math.round(myHtml.slice(split+1,myHtml.length-1)*1000000)/1000000;
                    document.collector.latitude.value=x;
                    document.collector.longitude.value=y;
                    lat="<br />Latitude: " + x;
                    lon="<br />Longitude: " + y;
                    latlon=""+lat+lon;
    
                    //map.openInfoWindow(latlng, latlon);
                    map.clearOverlay();
                    showMarker(latlng);
                }
            });
            map.addControl(new GLargeMapControl3D());
            map.addControl(new GMapTypeControl());
        }
    }
    

    It works by using a variable, showMarker, containing a reference to a function. This starts out pointing to a function, showNewMarker, which creates a marker, adds it to the map, and then changes showMarker to point to the function updateExistingMarker, which simply uses setLatLng to move the marker to a new position. This means that, on subsequent clicks, the existing marker will be moved to the location of the click.

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

Sidebar

Ask A Question

Stats

  • Questions 282k
  • Answers 282k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use psutil (https://github.com/giampaolo/psutil), which works on Windows and… May 13, 2026 at 4:00 pm
  • Editorial Team
    Editorial Team added an answer There are a few solutions out there, if you want… May 13, 2026 at 4:00 pm
  • Editorial Team
    Editorial Team added an answer This occurs because local values override style values. (Properties set… May 13, 2026 at 4:00 pm

Related Questions

I'm a user of Aquamacs under OS X, which by default does not recognize
I have a use case where a servlet (that has reasonably high concurrent use)
I'm setting up some Selenium tests for an internal web app and looking for
so after a few weeks, i have got my head around asp.net mvc and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.