Google지도/Places API를 사용하여 매우 간단한 애플리케이션을 설정하려고 애쓰다.
.controller('MainCtrl', [
'$scope',
'$http',
function($scope, $http){
$scope.userLocation = [];
$scope.currentLocation = function() {
$http({
method: 'GET',
url: 'https://www.googleapis.com/geolocation/v1/geolocate?key=xxx'
}).then(function successCallback(response) {
$scope.userLocation.push(response);
});
}
}])
문제 :
나는 성공적으로 위치 정보 서비스를 사용할 수 있습니다 내가 그들의 장소 API에 유사한 GET 요청을하려고하면 - 나는 얻을 CORS 오류 :
XMLHttpRequest cannot load https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=36.23…5.1458888&type=bar&key=xxx. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://0.0.0.0:3000' is therefore not allowed access.
질문 : 각도에서 이러한 유형의 요청을 할 수 있습니까, 아니면 백엔드를 설치해야합니까? 대신 그 전화를하니?
CORS 문제를 통과 한 방법으로 JSONP를 사용했지만 데이터에 액세스 할 수 없다는 문제가있었습니다. 그것은 잘못된 JSON은 ...하지만 그것은 Unexpected identifier :
을 말한다, 그리고 확실하지 경우에 나는 그것이 나에게 완벽하게 정상적으로 데이터처럼 보이는 소스 볼 때 : 라이브러리는 구글에 포함 통해 당신은 클라이언트 측에서 장소 API를 사용할 수 있습니다
{
"html_attributions" : [],
"results" : [
{
"geometry" : {
"location" : {
"lat" : 36.2388477,
"lng" : -115.1540073
},
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
"id" : "578bfba1f17b0c5fbdafd5b71600b50d3e95c1ca",
"name" : "Ruby Tuesday",
"opening_hours" : {
"open_now" : true,
"weekday_text" : []
},