Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

300
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!