Cómo eliminar el marcador antiguo y luego establecer el nuevo marcador de intervalo... Estoy llamando a una API y trazando nuevos marcadores después de unos segundos de setinterval. Los nuevos marcadores se trazan, pero el anterior aún permanece. Quiero borrar el marcador anterior cuando se trazan los nuevos marcadores. Aquí está mi código.
window.setInterval(selectLocation, 1000); var map,mIcon; function initMap() { var myOptions = { zoom: 17, center: new google.maps.LatLng(18.803535629803218, 98.95209518731684), mapTypeId:google.maps.MapTypeId.ROADMAP }; mIcon = { path: google.maps.SymbolPath.CIRCLE, fillColor: "green", fillOpacity: 0.8, strokeOpacity: 0.5, strokeWeight: 6, strokeColor: '#1b7709', scale: 30 }; map = new google.maps.Map(document.getElementById('map_canvas'), myOptions); infowindow = new google.maps.InfoWindow({ map:map, }); } let json; let marker = []; function selectLocation(){ $.ajax({ type:"POST", url: "json_location.php", }).done(function(text){ json = $.parseJSON(text); for(var i = 0 ;i<json.length;i++){ var lat = json[i].lat; var lng = json[i].lng; var id_local = json[i].id_local; var name_local = json[i].name_local; var latlng = new google.maps.LatLng(lat,lng); var id = i; marker = new google.maps.Marker({ map:map, html:id, position:latlng, icon: mIcon, label: {color: '#FFF', fontSize: '14px', fontWeight: '600', text: json[i].id_local}, title: json[i].id_local, }) }) }