-1

I have a button which simulates the heatmap. I use setInterval function when the button onclicked

 <button onclick="setInterval(function(){update_map()},50);">simulate</button>

My function is below:

function update_map(){
  counter+=50;
  var i =1
  for(i=counter-50;i<<?php echo json_encode($lat); ?>.length & i<counter;i++){
  taxiData.push(new google.maps.LatLng(<?php echo json_encode($lat); ?>[i],<?php echo json_encode($log); ?>[i]));
 }
  var pointArray = new google.maps.MVCArray(taxiData);
heatmap = new google.maps.visualization.HeatmapLayer({
    data: pointArray
  });

  heatmap.setMap(map);
  if(i==<?php echo json_encode($lat); ?>.length )
  clearInterval(setInterval(function(){update_map()},50));
}

Any kind of help or suggestion will be appreciated.

MIRMIX
  • 1,052
  • 2
  • 14
  • 40
  • Check the [docs](https://developer.mozilla.org/en-US/docs/Web/API/Window.setInterval). `setInterval` returns a id number that can be used in a subsequent call to [clearInterval](https://developer.mozilla.org/en-US/docs/Web/API/Window.clearInterval). – Matt Burland Jul 15 '14 at 13:11

1 Answers1

5

Pretty simple. Set the interval to a variable then clear it.

var refreshIntervalId = setInterval(fname, 10000);

/* later */
clearInterval(refreshIntervalId);

Stop setInterval call in JavaScript

Community
  • 1
  • 1
pattmorter
  • 991
  • 9
  • 21