how to hide previous markers when new markers added in google map javascript api
PHP Snippet 1:
const THRESHOLD = 3 // up to 3 active markers
let list = [] // list of markers
const onAddMarker = marker => {
// init marker
let marker = new google.maps.Marker([...opts])
// push marker to list
list.push(marker)
// check list length and remove oldest marker (if needed)
if (list.length > THRESHOLD)
list.shift().setMap(null)
}