PDA

View Full Version : settimeout works how?



bluewalrus
10-06-2009, 01:31 AM
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
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>

forum_amnesiac
10-06-2009, 08:07 AM
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


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

bluewalrus
10-10-2009, 05:22 AM
Nah, didnt work but thanks for the attempt I got a work around that worked out.