How to move marker smoothly without blinking in map

前端 未结 1 1039
余生分开走
余生分开走 2021-01-13 12:53

I have problem in my markers every time I get request to our server to get the newly location of my devices and updated the position of my markers on the map,when my vehicle

相关标签:
1条回答
  • 2021-01-13 13:16

    If you don't want them to flicker, don't "remove" them from the map, update their position.

    var map;
    var marker;
    var markerarray =[];
    
    setInterval(function(){
      $.ajax({
        type: "post",
        url: "vehiclecordinates.php",
        success: function(data){
          coordinates = data.latlng;
          vehiclename = data.vehiclename;
          for (var i = 0; i < coordinates.length; i++) {
            newcoordinate = new google.maps.LatLng(coordinates[i].split(",")[0],coordinates[i].split(",")[1]);
            if (markerarray[vehiclename[i]] && markerarray[vehiclename[i]].setPosition){
              markerarray[vehiclename[i]].setPosition(newcoordinate);
            else {
              marker =  new MarkerWithLabel({
                map:map,
                labelClass: "mylabels",
                labelStyle: {opacity: 1.0},
                labelContent: '<div>'+ vehiclename[i]+'</div>',
                icon:{
                  //some options here
                }
              });
              marker.setPosition(newcoordinate);
              markerarray[vehiclename[i]] = marker;
            }
          }
        }
      });
    },5000);
    

    See example based off the example in this similar question

    0 讨论(0)
提交回复
热议问题