I have to use Google Maps Distance Matrix API https://developers.google.com/maps/documentation/distance-matrix/intro to calculate the distance between two points with some coordinates. I use AngularJS and $http.jsonp() method to perform a request to the API:
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;
});
}
});
I get a response with status 'OK', but can`t handle it due to the next error:
How can I solve it? Thanks in advance for help