2016-07-02 2 views
1

Google Maps Distance Matrix API https://developers.google.com/maps/documentation/distance-matrix/intro 을 사용하여 좌표가있는 두 점 사이의 거리를 계산해야합니다. 내가 API에 요청 수행하고 $ http.jsonp() 메소드 AngularJS와를 사용

var app = angular.module('delivery', []); 
app.controller('deliveryCtrl', function ($scope, $http) { 
    $scope.submit = function() { 
      var googleStr = 'https://maps.googleapis.com/maps/api/distancematrix/json?&origins='; 
      var fromPlace = autocompleteFrom.getPlace(); 
      googleStr += fromPlace.geometry.location.lat() + ',' + fromPlace.geometry.location.lng(); 
      googleStr += "&destinations=" 
      var toPlace = autocompleteTo.getPlace(); 
      googleStr += toPlace.geometry.location.lat() + ',' + toPlace.geometry.location.lng(); 
      googleStr +='&key='+ apiKey+'&callback=JSON_CALLBACK'; 

      $http.jsonp(googleStr).success(function (data) { 
       console.log(data); 
      }).error(function (data) { 
       $scope.error = true; 
      }); 
    } 
}); 

나는 상태로 응답을받을를 'OK',하지만 인해 다음 오류로 취급은`t : enter image description here

어떻게 해결할 수 있습니까? 도움을 미리 요청 해 주셔서 감사합니다.

답변

1

제공된 링크를 통해 API 출력 JSON 및 XML에 대한 두 가지 옵션을 제공합니다. 이들 중 어느 것도 JSONp가 아닙니다. JSONp를 사용하려면 API가이를 허용하고 지원해야합니다.

API를 사용하려면 CORS 또는 JSONp를 통해 전화를 직접 프록시해야합니다. 다음과 같은 대답이 도움이 될 것입니다.
Loading cross domain endpoint with jQuery AJAX

관련 문제