Solved

Google map remove markers

Posted on 2008-10-18
2
10,829 Views
Last Modified: 2012-05-05
I'm using the following to find the lat and long of a point when a user clicks on the map.  I only want the current marker displayed when a user clicks.  currently the markers stay there.  however you can remove them by clicking on the marker.  

I want only one marker displaying at a time.  the current marker with the current coordinates.
<script type="text/javascript"> 

    //<![CDATA[ 

 

    var map = new GMap(document.getElementById("map")); 

    map.centerAndZoom(new GPoint(-92.27722, 34.74875), 4); 

 

    var point = new GPoint(-92.27722, 34.74875); 

    var marker = new GMarker(point); 

    map.addOverlay(marker); 

 

    GEvent.addListener(map, 'click', function(overlay, point) { 

 

        if (overlay) { 

            map.removeOverlay(overlay); 

 

      } else if (point) { 

 

            map.recenterOrPanToLatLng(point); 

            var marker = new GMarker(point); 

            map.addOverlay(marker); 

 

     } 

 

     }); 

 

// Recenter Map and add Coords by clicking the map 

GEvent.addListener(map, 'click', function(overlay, point) { 

            document.getElementById("latbox").value=point.y; 

            document.getElementById("lonbox").value=point.x; 

}); 

    //]]> 

    </script>

Open in new window

0
Comment
Question by:jimfrith
2 Comments
 
LVL 16

Accepted Solution

by:
sh0e earned 500 total points
ID: 22750113

map.clearOverlays();

Open in new window

0
 

Author Closing Comment

by:jimfrith
ID: 31507487
Perfect, Thanks for that!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Using Quotation Marks in PHP This question (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28217211.html) seems to come up a lot for developers who are new to PHP.  And it got me thinking, "How can we explain the rule…
Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now