gruntjs - cors issue with google places api using angularjs(yeoman) -
i trying configure google places api , display search results using angularjs. i've generated angular using yeoman , serving using 'grunt'. i'm using find "sport" results around location.
angular.module('frontendapp') .controller('httpreqcontroller', ['$scope', '$http', function($scope,$http) { console.log('next on click'); $scope.myfunction = function() { console.log('on click in place'); $http.get('https://maps.googleapis.com/maps/api/geocode/json?address='+ $scope.address+ '&key=<api_key>') .success(function (response) { $scope.names = response; var location = response.results[0]; console.log(location.geometry.location); // http request find sport around users place var comurl2 ='https://maps.googleapis.com/maps/api/place/nearbysearch/json?location='+ location.geometry.location.lat+ ','+ location.geometry.location.lng+ '&radius=50000&types='+ $scope.sport+ '&name='+ $scope.sport+ '&key=<api_key>'; $http.get(comurl2).success(function (response) { $scope.names = response; console.log(response); }); }); }; }]);
this gives me error on console
next on click search.js:23 on click in place search.js:30 object {lat: 48.1603191, lng: 8.8528498} xmlhttprequest cannot load https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=48.16…types=badminton&name=badminton&key=<api_key>. no 'access-control-allow-origin' header present on requested resource. origin 'http://localhost:9000' therefore not allowed access.
i've tried adding cors headers in gruntfile.js
connect: { options: { port: 9000, // change '0.0.0.0' access server outside. hostname: 'localhost', livereload: 35729 }, livereload: { options: { open: true, middleware: function (connect) { return [ connect.static('.tmp'), connect().use( '/bower_components', connect.static('./bower_components') ), connect().use( '/app/styles', connect.static('./app/styles') ), connect.static(appconfig.app) function(req, res, next) { res.setheader('access-control-allow-origin', '*'); res.setheader('access-control-allow-methods', '*'); next(); }, ]; } } },
but error persists.
any ideas i'm making mistake?
Comments
Post a Comment