I am trying to make this map only allow one marker on the page at any time but when I click a new marker is placed along with old ones.
Does anyone know how you would make this happen?
google.maps.event.addListener(map, 'click', function(event) {
//set up variables
var clickLat = event.latLng.lat();
var clickLng = event.latLng.lng();
//show lat and long
var loc = document.getElementById("location");
var info = "Latitude: "+clickLat+" "+", longitude: "+clickLng;
loc.innerHTML = info;
//place marker
var marker = new google.maps.Marker({
position: new google.maps.LatLng(clickLat, clickLng),
map: map,
animation: google.maps.Animation.DROP
});
});
I believe your answer is in the Google Mapa API. You just have to set the map of your old marker to null.
Read this: http://code.google.com/apis/maps/documentation/javascript/overlays.html#RemovingOverlays