Updating the data I bring it to the log everything is ok I get the updated data, but when I insert it in practice, I get:

Uncaught ReferenceError: znak is not defined

but the actual code

znac=setInterval(function (){ znak= parseFloat($('td').eq(2).html()); },1000); znac=setInterval(function (){ lng0= parseFloat($('td').eq(2).html()); },1000); myLatLng ={lat:znak,lng:lng0}; var cntrik = {lat:40.394508, lng:49.7148758}; var map = new google.maps.Map(document.getElementById('map'), { zoom: 6, center: cntrik }); var marker = new google.maps.Marker({ position: myLatLng, map:map, title: 'Hello World!' }); var intervalId=setInterval(function (){ marker.setMap(null); console.log('udalen'); marker.setMap(map); console.log('zamenen'); console.log(znak); },5000); } 
  • znak = parseFloat ($ ('td'). eq (2) .html ()); there is no space after znak - pnp2000
  • I would suggest not to torture javascript, but to use the setPosition method. - Grundy
  • Do you have two different variables - znac and znak ? - Kromster
  • 7
    Latin transliteration in the code is of course that still eye pain - SLy_huh
  • one
    @SLy_huh, a matter of habit - Grundy

2 answers 2

1) The main problem: where you did not declare the variable znak ;
2) Why create two identical intervals with the same time interval? If you can push all the values ​​in one

 var znak = parseFloat($('td').eq(2).html()) || 0, lng0 = znak; var znac = setInterval(function (){ znak = lng0 = parseFloat($('td').eq(2).html()); },1000); myLatLng = {lat: znak, lng: lng0}; var cntrik = {lat:40.394508, lng:49.7148758}; var map = new google.maps.Map(document.getElementById('map'), { zoom: 6, center: cntrik }); var marker = new google.maps.Marker({ position: myLatLng, map:map, itle: 'Hello World!' }); var intervalId = setInterval(function (){ marker.setMap(null); console.log('udalen'); marker.setMap(map); console.log('zamenen'); console.log(znak); }, 5000); 
  • Comments are not intended for extended discussion; conversation moved to chat . - Nick Volynkin

In order to be able to get the value of a variable, it must be declared.

In this code, an attempt is made to get the value of the variable znak before its implicit declaration goes by assigning timer functions to it.

Similarly with lng0 .


By assigning the result of the second setInterval variable znac, the reference to the first timer is lost and can no longer be stopped. It’s probably worth moving it all to one timer.

  • so why does everything work in console.log - elik
  • an example is possible, I don’t quite understand you, but with an example I’ll understand I think, although I doubt that it’s about the links here. The console displays everything - elik
  • You should not change the body of the question by transferring the code from the answers into it. There is no console.log in it now - Grundy
  • @elik, I have an example in response. Take a look - Yuri