控制台打印语句乱序

时间:2014-08-13 13:39:44

标签: javascript console flow

在下面的代码中,我通过谷歌地图Places API一组坐标并检索本地商业信息。我不明白为什么以下代码无序触发。下面的控制台语句应按此顺序排列,但正如您在下面看到的那样,它们不是。

"Loop iteration: 0"
"PlacesSearchFunction Step 1"
"Calling PlacesServiceFunction to GoogleMaps API - Step 2"
" Step 3"
"End of PlacesSearch Step 4"
"final Function Starting Step 5"


   run();

   function finalFunction(myBusinessName,results) {

       console.log("final Function Starting Step 5"); 
       .... 


   function placesSearch(myBusinessName,myLatlng) {           

        count = 0;

        console.log("PlacesSearchFunction Step 1");

        //search redius
        var request = {
            location: myLatlng,
            radius: '5000'
        };

        var service = new google.maps.places.PlacesService(map);     

        service.nearbySearch(request, function(results, status) {

            console.log("Calling PlacesServiceFunction to GoogleMaps API Step 2")

            if (status == google.maps.places.PlacesServiceStatus.OK) {
                console.log("Step 3");
            }

            else {    
                console.log("Step 3");               
            }

            console.log("End of placesSearch Step 4");
            finalFunction(myBusinessName,results);
        });           
    }

    } 

    function run() { 
        var count = 0;           
        for (var key in placeObject) {
            if (placeObject.hasOwnProperty(key)) {                    
                console.log("Loop Iteration:" + count++);
                placesSearch(key, placeObject[key]);
            }
        }
    }


"Loop iteration: 0"
"PlacesSearchFunction Step 1"
"Loop iteration: 1"
"PlacesSearchFunction Step 1"
"Loop iteration: 2"
"PlacesSearchFunction Step 1"
"Loop iteration: 3"
"PlacesSearchFunction Step 1"

....Continued to....

"Loop iteration: 29"
"PlacesSearchFunction Step 1"
"Loop iteration: 30"
"PlacesSearchFunction Step 1"
"Calling PlacesServiceFunction to GoogleMaps API - Step 2"
" Step 3"
"End of PlacesSearch Step 4"
"final Starting Step 5"
TypeError: results is null 
"Calling PlacesServiceFunction to GoogleMaps API - Step 2"
" Step 3"
"End of PlacesSearch Step 4"
"final Starting Step 5"
"Calling PlacesServiceFunction to GoogleMaps API - Step 2"
" Step 3"
"End of PlacesSearch Step 4"
"final Starting Step 5"
"Calling PlacesServiceFunction to GoogleMaps API - Step 2"
" Step 3"
"End of PlacesSearch Step 4"
"final Starting Step 5"
"Calling PlacesServiceFunction to GoogleMaps API - Step 2"
" Step 3"
"End of PlacesSearch Step 4"
"final Starting Step 5"
"Calling PlacesServiceFunction to GoogleMaps API - Step 2"
" Step 3"
"End of PlacesSearch Step 4"
"final Starting Step 5"
"Calling PlacesServiceFunction to GoogleMaps API - Step 2"
" Step 3"
"End of PlacesSearch Step 4"
"final Starting Step 5"
"Calling PlacesServiceFunction to GoogleMaps API - Step 2"
" Step 3"
"End of PlacesSearch Step 4"
"final Starting Step 5"
"Calling PlacesServiceFunction to GoogleMaps API - Step 2"
" Step 3"
"End of PlacesSearch Step 4"
"final Starting Step 5"
"Calling PlacesServiceFunction to GoogleMaps API - Step 2"
" Step 3"
"End of PlacesSearch Step 4"
"final Starting Step 5"
"Calling PlacesServiceFunction to GoogleMaps API - Step 2"
" Step 3"
"End of PlacesSearch Step 4"
"final Starting Step 5"

0 个答案:

没有答案