Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

311
Vistas
Google map clear old markers....when new markers?

How to remove old marker and Then setInterval new marker...I'm calling an API and plotting new markers after few seconds setinterval. The new markers get plotted but the old one still remains. I want to clear the old marker when the new markers are plotted. Here is my code.

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,

        })

    })

}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda