Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Google在搜索请求后放置结果(使用Angular)_Javascript_Angularjs_Google Maps Api 3_Google Places Api - Fatal编程技术网

Javascript 使用Google在搜索请求后放置结果(使用Angular)

Javascript 使用Google在搜索请求后放置结果(使用Angular),javascript,angularjs,google-maps-api-3,google-places-api,Javascript,Angularjs,Google Maps Api 3,Google Places Api,我有下面的代码,但是我想在角度“$scope.”变量中使用PlaceService(map).search(request)返回的数据 目前,我有一个回调函数,用结果数据分配一个新数组,但是Angular$scope变量无法访问它,因为GooglePlaces是异步的 我可以看到两种方法,但我不太确定如何执行它们。 据我所见,我可以: 1) 在findPlaces()函数中访问搜索结果,无需回调 或 2) 将$scope变量传递到回调函数“storeResults”中 function find

我有下面的代码,但是我想在角度“$scope.”变量中使用
PlaceService(map).search(request)
返回的数据

目前,我有一个回调函数,用结果数据分配一个新数组,但是Angular$scope变量无法访问它,因为GooglePlaces是异步的

我可以看到两种方法,但我不太确定如何执行它们。 据我所见,我可以:

1) 在findPlaces()函数中访问搜索结果,无需回调

2) 将$scope变量传递到回调函数“storeResults”中

function findPlaces(addrLocation, $scope) {
// Geocoder already started

// prepare variables (filter)
var type = myType;
var radius = document.getElementById('radius').value;

// prepare request to Places
var request = {
    location: addrLocation,
    radius: radius,
    types: [type]
};

    // send request
    service = new google.maps.places.PlacesService(map);
    service.search(request, storeResults);
}

函数存储结果(结果、状态){
//确保找到东西
if(status==google.maps.places.PlacesServiceStatus.OK){
//首先,我们清除以前找到的地方的列表
clearResults();

对于(var i=0;i),你可以在Angular应用程序的范围之外更新你的
范围
变量,通过使用感谢,这个链接帮了我很多忙。
function storeResults(results, status) {
//Ensure something is found
if (status == google.maps.places.PlacesServiceStatus.OK) {
    //First we clear the list of previously found places
    clearResults();
    for (var i = 0; i <= results.length-1; i++) {
        setCREsults(results[i]);
       //alert(searchResults[i].name + ' ' + searchResults[i].address);
    }
}
else if (status == google.maps.places.PlacesServiceStatus.ZERO_RESULTS) {
    alert('Sorry, nothing is found');
}