我試圖發送一個請求在我的angularjs應用程序到谷歌API來獲取在一個位置周圍的半徑景點。但是我在chrome中收到此錯誤消息: 請求的資源上沒有「Access-Control-Allow-Origin」頭。因此不允許訪問原產地'http://localhost:9000'。當發送請求到谷歌API時訪問控制允許來源
我試過json和jsonp,但結果是一樣的。 :S
$http.get('https://maps.googleapis.com/maps/api/place/radarsearch/json?location=51.503186,-0.126446&radius=5000&type=museum&key=<MYKEY>')
.then(function(response) {
$scope.dataResult = response.data;
});
$scope.getlocation = function() {
$scope.method = 'GET';
$http({ method: $scope.method, url: "https://maps.googleapis.com/maps/api/place/radarsearch/json?location=51.503186,-0.126446&radius=5000&type=museum&key=<MYKEY>&callback=JSON_CALLBACK" }).
success(function(data, status) {
$scope.status = status;
$scope.data = data;
console.log(data);
}).
error(function(data, status) {
$scope.data = data || "Request failed";
$scope.status = status;
});
};
我不想在地圖上顯示結果,我只希望列表格式。
問題是你的起源是'http',你的目的地是'https'。讓這兩者平等。 – georgeawg