Angularjs 无法从http请求加载图像

Angularjs 无法从http请求加载图像,angularjs,cordova,ionic-framework,Angularjs,Cordova,Ionic Framework,我正在尝试从谷歌地图街景API获取图像,以下是我的服务: .factory('WeatherService', function($http) { var GOOGLEMAP_KEY ="AIzaSyBZRxxrYsNGfIfUbGRCT1k948wAV-rwLGY"; var urlGoogleStreetView = 'https://maps.googleapis.com/maps/api/streetview?key=' + GOOGLEMAP_KEY + '&si

我正在尝试从谷歌地图街景API获取图像,以下是我的服务:

.factory('WeatherService', function($http) {
   var GOOGLEMAP_KEY ="AIzaSyBZRxxrYsNGfIfUbGRCT1k948wAV-rwLGY";

   var urlGoogleStreetView = 'https://maps.googleapis.com/maps/api/streetview?key=' + GOOGLEMAP_KEY + '&size=480x320';

   return {
     pictureLocation: function (lat,lng,h,p){
         return $http.get(urlGoogleStreetView + '&location=' + lat + ',' + lng + '&heading=' + h + '&pitch=' + p);
     }
   };
});
这就是我在控制器中对它的称呼:

$scope.imageSource=WeatherService.pictureLocation(46.414382,10.013988,151.78,-0.76);
在视图中,它显示断开的图像,并给我“Get404(NotFound)”错误,但当我手动调用它时

$scope.imageSource="https://maps.googleapis.com/maps/api/streetview?key=AIzaSyBZRxxrYsNGfIfUbGRCT1k948wAV-rwLGY&size=480x320&location=46.414382,10.013988&heading=151.78&pitch=-0.76";
图像完全加载。有人能帮我吗

这是我的HTML

<ion-content scroll="true" ng-controller="HomeCtrl">

  <h3>{{city}}</h3>
  <h5><weather-icon icon="current.currently.icon" id="current-icon"></weather-icon> {{current.currently.summary}}</h5>
  <span class="large">{{current.currently.temperature}} &deg; </span><br>
  <img ng-src="{{imageSource}}">

</ion-content>

{{城市}
{{current.current.summary}
{{current.current.temperature}}°

如果您对%7B%7D进行url解码,它会给您{},这意味着$scope.imageSource返回一个空对象。您需要检查WeatherService.pictureLocation(46.414382,10.013988151.78,-0.76)


正在返回图像的路径而不是空对象。

我的英语很差,但我会尽力解释

ng src应等于url字符串。
$scope.imageSource=WeatherService.pictureLocation(46.414382,10.013988151.78,-0.76)
,则
$scope.imageSource
是图像数据,而不是url字符串

$scope.imageSource=”中https://maps.googleapis.com/maps/api/streetview?key=AIzaSyBZRxxrYsNGfIfUbGRCT1k948wAV-跑道长度和尺寸=480x320,位置=46.414382,10.013988,航向=151.78,螺距=-0.76”,,
$scope.imageSource
是一个url字符串

因此,使用服务将显示错误

所以你可以像这样编辑你的代码

.factory('WeatherService', function() {
var GOOGLEMAP_KEY ="AIzaSyBZRxxrYsNGfIfUbGRCT1k948wAV-rwLGY";

var urlGoogleStreetView = 'https://maps.googleapis.com/maps/api/streetview?key=' + GOOGLEMAP_KEY + '&size=480x320';

return {
 pictureLocation: function (lat,lng,h,p){
     return urlGoogleStreetView + '&location=' + lat + ',' + lng + '&heading=' + h + '&pitch=' + p;
     }
 };
});

你说得对。我不需要发出http请求,而是直接返回url字符串。谢谢