Skizit
Skizit

Reputation: 44862

Show only 1 marker at a time fron onClick

I've got the following onClick function...

     GEvent.addListener(map, "click", function(overlay, latLng)
{
    if (latLng) {
 marker = new GMarker(latLng, {draggable:true});
 marker.openInfoWindowHtml(mes);
  }
  // display the lat/lng in your form's lat/lng fields
    document.getElementById("lat").value = latLng.lat();
    document.getElementById("lng").value = latLng.lng();

});

basically I want to make it so only a marker shows on the most recent click. I've been looking at this question Googlemaps - removing previous marker but can't really figure out how I'd apply that to my code. could someone help me out?

Thanks.

Upvotes: 0

Views: 171

Answers (1)

CrazyEnigma
CrazyEnigma

Reputation: 2834

One could use a variable within an object, and determine whether that variable has been set where it tracks the current marker that is visible, and set the marker to be invisible, unset it before adding the marker that is currently being shown.

Upvotes: 1

Related Questions