js 中 函数的返回值问题

时间:2020-12-21 23:24:59
var result=''; 
function searchByStationName(    address   ) {
   // map.clearOverlays();//清空原来的标注
    var keyword = address    ;
    localSearch.setSearchCompleteCallback(function (searchResult) {
        var poi = searchResult.getPoi(0);
        result = poi.point.lng + "," + poi.point.lat;      
    });
    localSearch.search(keyword);  
    return result ;
    } 

  请教大侠们,如上方法是为了实现根据地址查询经纬度,但测试发现返回值为"";

为何 result = poi.point.lng + "," + poi.point.lat;     这句代码没有实现为result赋值呢?