简体   繁体   中英

Previous marker remove in google map

Tried to create moving marker. But the marker create new not moving the same. I want moving marker with remove previous marker

function makeMarker(map) { 
     var icons = 'images/tvsxl.png';

  setInterval(function(){   var markers = []; 
    $.post( "ajaxload.php?shop_id=<?php echo $outlet_id?>", function(data) {  
        var obj = $.parseJSON(data);
        var value = obj['data'];
        //console.log(value.length);
        for (i = 0; i < value.length; i++) {  

        var myLatLng = new google.maps.LatLng(value[i].latitude ,value[i].longitude);
        var marker = new google.maps.Marker( {position: myLatLng, map: map,icon: icons,title:value[i].name} );

        markers.push(marker); 
        markers[i].setMap( map );

         }  


    }); 

}, 3000);

Try to clear old markers before placing a new ones

for(var i=0; i<markers.length; i++){
         markers[i].setMap(null);
    }
    //clear old markers form array
    markers = [];

尝试这个

markers[marker-index-value].setMap( null);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM