-1

how would i call the myVar again so it will restart the interval with a onclick Event.

  var myVar = setInterval(function(){ myTimer() }, 1000);

function myTimer() {
    map.panTo(currentPositionMarker.getPosition());
}


google.maps.event.addListener(map, 'dragstart', function() {

     clearInterval(myVar);

  });

1 Answers1

0

myVar is not a function, it can't be "called".

Also a timer can't be "re-started", when you call clearInterval, the timer will be deleted, not "stopped".

You must create a new timer, e.g. :

var myFnc=function(){ return setInterval(myTimer,1000); },
    myVar=myFnc();

function myTimer() {
    map.panTo(currentPositionMarker.getPosition());
}

google.maps.event.addListener(map, 'dragstart', function() {
     clearInterval(myVar);
});

google.maps.event.addListener(currentPositionMarker, 'click', function() {
     clearInterval(myVar);
     myVar=myFnc();
});
Dr.Molle
  • 116,463
  • 16
  • 195
  • 201