Link to home
Start Free TrialLog in
Avatar of jimfrith
jimfrith

asked on

Google map remove markers

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

ASKER CERTIFIED SOLUTION
Avatar of sh0e
sh0e

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jimfrith
jimfrith

ASKER

Perfect, Thanks for that!