Results 1 to 3 of 3

Thread: settimeout works how?

  1. #1
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default settimeout works how?

    I've found the setTimeout function(class, method, ?) but I either don't understand it, don't have it functioning right, or it's not used the way I need it to be. Below is my code. I'm trying to put in a pause between when it goes to the "addToMap" and returns. Right now this outputs all the addresses (30) then loads 30 alert windows. My goal is to have one address then one alert window then the next address and the next alert widnow (in the end i dont want the alerts but I'm using this for debug method right now). There is more javascript but this is the limited code if you need more please let me know and this is inside of a script type text/javascript tag.

    PHP Code:
            <?php
            
    while ($increase2 $increase ) {
            
    ?>
            address2 = address;
            setTimeout('alert("test");', 1700);
            var address = "<?php echo $City[$increase2] . ", ";?> <?php echo $State[$increase2] . ", ";?> <?php echo $Country[$increase2]. ", ";?>";
            if (address2 != address) {
            geocoder.getLocations(address, addToMap);
            }
            <?php
            $increase2
    ++;
            }
            
    ?>
        }
       function addToMap(response)
       {
          // Retrieve the object
          place = response.Placemark[0];
          // Retrieve the latitude and longitude
          point = new GLatLng(place.Point.coordinates[1],
                              place.Point.coordinates[0]);
          bounds.extend(point);
            map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));

          // Create a marker
          marker = new GMarker(point);
          // Add the marker to map
          map.addOverlay(marker);
          // Add controls and zoom to map    
          map.addControl(new GSmallMapControl());
          map.addControl(new GMapTypeControl());
          // Add address information to marker
          //marker.openInfoWindowHtml(place.address);
       }
        //]]>
        </script>

  2. #2
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    I dont know if it's relevant but I found that the setTimeout function didn't seem to work as a delay if it was inside the original function.

    When I moved it out and then called it, it worked as I expected.

    eg

    HTML Code:
    function test(){
               address2 = address;
            timeout();
            var address = "<?php echo $City[$increase2] . ", ";?> <?php echo $State[$increase2] . ", ";?> <?php echo $Country[$increase2]. ", ";?>";
    }
    
    function timeout() {
    	setTimeout('alert("test");', 1700);
    	return;
    }
    May not work in this case but good luck

  3. The Following User Says Thank You to forum_amnesiac For This Useful Post:

    bluewalrus (10-10-2009)

  4. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Nah, didnt work but thanks for the attempt I got a work around that worked out.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •