www.webdeveloper.com
Results 1 to 2 of 2

Thread: Executing ForLoop delays consistently

  1. #1
    Join Date
    Nov 2011
    Posts
    1

    Exclamation Executing ForLoop delays consistently

    I have a bunch of longitude and latitude values sent to google maps V2 api but i cant seem to get the requests to match.
    So my code is set up where

    Onclick I have it read the longitude and latitude from textfile and send it to there geocoding server. I have that in a for loop which goes through each point it looks like this.
    Code:
    	function forLOOP(loc){
    
    	for (i=loc; i<=10000; i++){
    			
    			    count = i; 
    			
    				address2= "(" + address1[i] + "," + address1[i+1] + ")";
    				  makefile(address2,"C:\\test1.txt");
    				geocoder.getLocations(address2, showAddress);
    				doDelayLoop(count);
    			   i++
    				
    			}
    			}
    showAddress(){
    
    makefile(place.address,"C:\\test1.txt");
    
    }
    Where address2 is the text file in a split() array and then is sent to request geocoded values. When i get the response it doesnt seem to write it directly after in the text file. It ends up writing everything in the for loop first and then all the received requests.

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,330

    Lightbulb Need more information and clarification...

    While I obviously don't have your whole code to test against
    or even a link to look at, I can see one possible problem with this:
    Code:
    	function forLOOP(loc){
    
    	for (i=loc; i<=10000; i++){
    			
    			    count = i; 
    			
    				address2= "(" + address1[i] + "," + address1[i+1] + ")";
    				  makefile(address2,"C:\\test1.txt");
    				geocoder.getLocations(address2, showAddress);
    				doDelayLoop(count);
    			   i++
    				
    			}
    			}
    showAddress(){
    
    makefile(place.address,"C:\\test1.txt");
    
    }
    You reinitialize the variable "count" each time through the look
    and because of that have a different delay period for each call to the "doDelayLoop" function.

    At first glance, I don't think that is what you want to do.

    I would also suggest using a "setTimeout" function to create any delay
    as the "for...loop" logic may not work right (you do not show the "doDelayLoop function to examin)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles