2016-07-02 16 views
1

Google Maps Distance Matrix API https://developers.google.com/maps/documentation/distance-matrix/intro を使用して、ある座標で2点間の距離を計算する必要があります。

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」ステータスで応答を得るが、原因、次のエラーにそれを処理can`t: enter image description here私はAngularJSとAPIへのリクエストを実行するには、$ http.jsonp()メソッドを使用します

どうすれば解決できますか?事前にお手伝いしていただきありがとうございます

答えて

1

提供されたリンクから、API出力のJSONとXMLの2つのオプションが得られます。どちらもJSONpではありません。 JSONpを使用するには、APIがそれを許可してサポートする必要があります。

APIを使用する場合は、CORSまたはJSONp経由で呼び出しをプロキシする必要があります。次の回答はおそらくあなたを助けるでしょう:
Loading cross domain endpoint with jQuery AJAX

関連する問題