Solved

Google map remove markers

Posted on 2008-10-18
2
10,831 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

803 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