Answer the question
In order to leave comments, you need to log in
What could be the problem of getting Yandex API data via angular $http.jsonp?
Good day to all! I'm new to angular and I'm having this problem. I'm trying to get data on the train schedule at the station in this way:
rTApp.controller('welcomeController', [ 'Stations','$scope','$http',function(Stations, $scope, $http ){
$scope.city = {name: "Moscow"};
$scope.setCity = function(address){
$http.get('http://maps.googleapis.com/maps/api/geocode/json', {params: {address: address}})
.success(function(data){
url = 'https://api.rasp.yandex.net/v1.0/nearest_stations/?&apikey={key_value}&lat='+data.results[0].geometry.location.lat + '&lng=' + data.results[0].geometry.location.lng+'&distance=50&lang=ru&transport_types=train&format=json&callback=JSON_CALLBACK';
$http.jsonp(url).
success(function(data, status, headers, config) {
console.log(data);
});
url = 'https://api.rasp.yandex.net/v1.0/nearest_stations/?&apikey={key_value}&lat='+data.results[0].geometry.location.lat + '&lng=' + data.results[0].geometry.location.lng+'&distance=50&lang=ru&transport_types=train&format=json';
function custom_callback(data) {
console.log(data);
}
rTApp.controller('welcomeController', [ 'Stations','$scope','$http',function(Stations, $scope, $http ){...............
url = 'https://api.rasp.yandex.net/v1.0/nearest_stations/?&apikey={key_value}&lat='+data.results[0].geometry.location.lat + '&lng=' + data.results[0].geometry.location.lng+'&distance=50&lang=ru&transport_types=train&format=json&callback=custom_collback';
$http.jsonp(url)
...............
}]);
Answer the question
In order to leave comments, you need to log in
Well, if for some reason the standard Angular callback does not work, you can put some service or something else into your custom_callback through a closure where you want to save the data.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question