Solved

Google map remove markers

Posted on 2008-10-18
2
10,835 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Geolocation works...sometimes 2 39
Make Float not to Wrap 15 66
javascript duplicates 9 25
XJS:  how to throw error if no match found 8 57
Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

738 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