JS 新手一名。
想查询江苏省下所有的耐克店的信息。
思路是先取到有耐克店的城市然后再通过城市名查询到信息都 push 到 results 数组里。
可是问题是 results 数组里面的值并没有完全存储进去。
求来解答。
代码如下
<script type="text/javascript">
var map = new BMap.Map ("allmap");
var lng;
var lat;
var searchInfoWindow = null;
var br=new Array ();
map.centerAndZoom (new BMap.Point (116.404, 39.915 ), 11 );
var local = new BMap.LocalSearch ("江苏省", {
renderOptions: {map: map, panel: "r-result"}
});
local.search ("nike");
local.setSearchCompleteCallback (function (rs ) {
var count=rs.getCityList ().length;
var city=rs.getCityList ()
for (var x=0 ;x<count;x++){
var local = new BMap.LocalSearch (city[x].city, {
renderOptions: {map: map, panel: "r-result"}
});
local.search ("nike");
var results = new Array ();
var i=0;
local.setSearchCompleteCallback (function (rs ) {
if (local.getStatus () == BMAP_STATUS_SUCCESS ) {
for (j = 0; j < rs.getCurrentNumPois (); j++) {
var poi = rs.getPoi (j );
var title= poi.title;
var lng = poi.point.lng;
var lat = poi.point.lat;
var addr = poi.address;
var result = {
addr: addr,
lng: lng,
lat: lat,
title: title
};
results.push (result );
}
if (rs.getPageIndex () != (rs.getNumPages ()+1 )) {
i = i + 1;
local.gotoPage (i );
}
console.log (results );
}
});
}
});
</script>
1
narrowei OP 感觉是 setSearchCompleteCallback 没有在 for 循环中执行
|