Javascript 如何将Google Maps API调用中的数据设置为变量?
我正在对Places库进行GoogleMapsAPI调用,目标是提取业务数据并在我的Angular应用程序中直观地使用它。到目前为止,我正在成功地从谷歌收回数据 但是,我很难将从API调用检索到的“place”数据分配给getGoogleData()函数之外的变量 我一直在尝试使用“return”和“.then”,但我一直无法让它工作。这是代码 函数getGoogleData(){ var service=newgoogle.maps.places.PlacesService(地图); var place={placeId:'ChIJr4vVw8-kwoAR0iEipIyAZWw'}; service.getDetails(地点、功能(地点、状态){ if(status==google.maps.places.PlacesServiceStatus.OK){ 如果(地点){ 控制台日志(位置); } } } ); } getGoogleData()代码> 将Javascript 如何将Google Maps API调用中的数据设置为变量?,javascript,angularjs,google-maps,Javascript,Angularjs,Google Maps,我正在对Places库进行GoogleMapsAPI调用,目标是提取业务数据并在我的Angular应用程序中直观地使用它。到目前为止,我正在成功地从谷歌收回数据 但是,我很难将从API调用检索到的“place”数据分配给getGoogleData()函数之外的变量 我一直在尝试使用“return”和“.then”,但我一直无法让它工作。这是代码 函数getGoogleData(){ var service=newgoogle.maps.places.PlacesService(地图); var
$scope.$apply()
添加到函数中
将$scope.$apply()
添加到函数中
function getGoogleData(){
var service = new google.maps.places.PlacesService(map);
var place = { placeId: 'ChIJr4vVw8-kwoAR0iEipIyAZWw' };
service.getDetails(place, function(place, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
if(place) {
console.log(place);
$scope.$apply();
}
}
}
);
}