'n' 天后删除 Google 地图上的标记,以消除实时数据的拥塞



我的Google地图上的标记是根据API JSON数据绘制的Google地图(LAT,LNG(。我只想在当前日期30天之前删除在地图上绘制的那些标记,以便当我不断填充地图时,标记会自动删除,看起来整洁而没有拥挤。

我在JavaScript中尝试了这样的事情:

var today = new Date(); //current date
var expire = new Date(current + (30 * 24 * 60 * 60 * 1000)); //expire after 30 days


if(today == expire){
  current = Date.now();
  setTimeout(function(){
      for(i=0; i<gmarkers.length; i++){
          gmarkers[i].setMap(null);
      }       
   }, 2000);
}

"当前"变量的值在开始时未定义。如何实现这一目标?

在浏览器中保存current执行以下操作:

var current;
if (localStorage.getItem('current')) {
    current = JSON.parse(localStorage.getItem('current'));
} else {
    current = Date.now();
    localStorage.setItem('current', JSON.stringify(current));
}

最新更新