【发布时间】:2016-03-04 19:04:39
【问题描述】:
我试图在我的 angularjs 应用程序中向谷歌 API 发送一个请求,以获取某个位置周围半径内的景点。但我在 chrome 中收到此错误消息: 请求的资源上不存在“Access-Control-Allow-Origin”标头。 Origin 'http://localhost:9000' 因此不允许访问。
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。使两者相等。
标签: angularjs google-api