javascript google places api textSearch - 如何获得循环结果?

时间:2014-05-23 17:48:57

标签: javascript google-places-api

对不起我的英文,拜托!我想获得有关我的坐标周围的一些地方的信息,并获得我的坐标和地方坐标之间的距离。

我的代码是

  function searchObj()
  {
    reiting = 0.0;
    for (i=0; i<objects.length-1; i++) {
    func(i);
  }
  setTimeout(console.log('end block'), 10000);
  }

  function func(i)
  {
    request = {
    location: marker.getPosition(),
    radius: '5000',
    query: objects[i]
    };
    service = new google.maps.places.PlacesService(map);
    service.textSearch(request, callback)
        console.log(i);
            console.log(objcom[i]);
            console.log(result);
            console.log(reiting);
            console.log('__________________');


  }

  function callback(results, status) {
  if (status == google.maps.places.PlacesServiceStatus.OK) {
      var place = results[0];
      console.log(google.maps.geometry.spherical.computeDistanceBetween(results[0].geometry.location, marker.getPosition()));
  }
  }

我希望获得有关&#34; for&#34;的所有迭代的距离信息,但我得到的是在js控制台:

0 app.js:91
2000 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
1 app.js:91
2000 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
2 app.js:91
2500 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
3 app.js:91
1500 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
4 app.js:91
2000 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
5 app.js:91
700 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
6 app.js:91
1000 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
7 app.js:91
500 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
8 app.js:91
1000 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
9 app.js:91
1000 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
10 app.js:91
1500 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
11 app.js:91
400 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
12 app.js:91
800 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
13 app.js:91
400 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
14 app.js:91
800 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
15 app.js:91
600 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
16 app.js:91
1500 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
17 app.js:91
1000 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
18 app.js:91
1000 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
19 app.js:91
3000 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
20 app.js:91
2000 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
21 app.js:91
5000 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
22 app.js:91
600 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
23 app.js:91
700 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
24 app.js:91
1300 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
25 app.js:91
300 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
26 app.js:91
800 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
27 app.js:91
200 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
28 app.js:91
1000 app.js:92
undefined app.js:93
0 app.js:94
__________________ app.js:95
block end app.js:79
14961.98138700165 app.js:103
2566.670589673884 app.js:103
555.8505810986642 app.js:103
3954.241697640822 app.js:103
3998.2274662548334 app.js:103
2189.354527008757 app.js:103
4005.958253326129 app.js:103
2542.8230258547974 app.js:103
4998.7611876712945 app.js:103
2362.048936147151 

我不明白为什么函数回调不会在&#34; for&#34;的迭代中向控制台返回值。它是&#34; for&#34;。

的所有迭代后的返回值

我怎么能得到?:

    0 app.js:91
    2000 app.js:92
    14961.98138700165 app.js:103
    0 app.js:94
    __________________ app.js:95
    1 app.js:91
    2000 app.js:92
    2566.670589673884 app.js:103
    0 app.js:94
    __________________ app.js:95
    2 app.js:91
    2500 app.js:92
    555.8505810986642 app.js:103
    0 app.js:94
    __________________ app.js:95

对不起我的英文,

0 个答案:

没有答案