locked
JavaScript problem of MAP control RRS feed

  • Question

  • Hi, all.
    A javascript problem occured in my web site. Could you please help me?
    I want to control the "car-icon.gif" to move in some time interval.
    When I use the source code of partA, it can work well.  While I change the source code to partB with loop control by "for()", it can not work.
    Anyone can tell me how to do?
    Thanks.  

    ---------------------------------------------------------------
        var arglat = 35.69031083620262;  
        var arglng = 139.70000267028814;
        timeinterval = 1000;


    partA:
    ------>>>>
        window.setTimeout(function() { AddPushpin(arglat, arglng + 0.0002, 'Vehicle 999231', 'Time: ' + new Date().toTimeString(), layer, 'car-icon.gif'); }, 2000);
        window.setTimeout(function() { AddPushpin(arglat, arglng + 0.0003, 'Vehicle 999232', 'Time: ' + new Date().toTimeString(), layer, 'car-icon.gif'); }, 3000);
        window.setTimeout(function() { AddPushpin(arglat, arglng + 0.0005, 'Vehicle 999233', 'Time: ' + new Date().toTimeString(), layer, 'car-icon.gif'); }, 5000);
        window.setTimeout(function() { AddPushpin(arglat, arglng + 0.0006, 'Vehicle 999234', 'Time: ' + new Date().toTimeString(), layer, 'car-icon.gif'); }, 6000);
        window.setTimeout(function() { AddPushpin(arglat, arglng + 0.0007, 'Vehicle 999235', 'Time: ' + new Date().toTimeString(), layer, 'car-icon.gif'); }, 7000);
        window.setTimeout(function() { AddPushpin(arglat, arglng + 0.0008, 'Vehicle 999236', 'Time: ' + new Date().toTimeString(), layer, 'car-icon.gif'); }, 8000);
        window.setTimeout(function() { AddPushpin(arglat, arglng + 0.0009, 'Vehicle 999237', 'Time: ' + new Date().toTimeString(), layer, 'car-icon.gif'); }, 9000);
    <<<-----


    partB:
    --------->>>>>
        for (var j = 0; j < 7; j++) {
            window.setTimeout(function() { AddPushpin(arglat, arglng + 0.0001, 'Vehicle XXXXXXXXXXXXXXXX', 'Time: ' + new Date().toTimeString(), layer, 'car-icon.gif'); }, tmptimeinterval);
            arglng = arglng + 0.0001;
            tmptimeinterval = tmptimeinterval + 1000;     
        }
    <<<<<----------


    frank
    Tuesday, April 7, 2009 5:55 AM

Answers

  • Hi,

    Looks like tmptimeinterval is not defined.  Up above you have it set as timeinterval (without a var declaration also).  See simplified sample code below:

     var arglat = 35.69031083620262;  
     var arglng = 139.70000267028814;
     timeinterval = 1000; 
       
      for (var j = 0; j < 2; j++) {
            window.setTimeout(function() { alert(arglat + arglng)}, tmptimeinterval);
            arglng = arglng + 0.0001;
            tmptimeinterval = tmptimeinterval + 1000; 
    Hope that helps,
    Infusion Development
    Tuesday, April 7, 2009 2:40 PM

All replies

  • Hi,

    Looks like tmptimeinterval is not defined.  Up above you have it set as timeinterval (without a var declaration also).  See simplified sample code below:

     var arglat = 35.69031083620262;  
     var arglng = 139.70000267028814;
     timeinterval = 1000; 
       
      for (var j = 0; j < 2; j++) {
            window.setTimeout(function() { alert(arglat + arglng)}, tmptimeinterval);
            arglng = arglng + 0.0001;
            tmptimeinterval = tmptimeinterval + 1000; 
    Hope that helps,
    Infusion Development
    Tuesday, April 7, 2009 2:40 PM
  • Thanks.

    frank
    Tuesday, April 7, 2009 3:23 PM