1
I have the following request in the Google API using $http Angularjs:
$http.get('http://maps.googleapis.com/maps/api/distancematrix/json?origins=Porto Alegre&destinations=Sao Paulo&mode=driving&language=pt-BR&sensor=false');
The problem is it returns the error:
Xmlhttprequest cannot load http://maps.googleapis.com/maps/api/distancematrix/json?origins=Porto%20Alegre&Destinations=Sao%20Paulo&mode=driving&language=en-Br&sensor=false. No 'Access-Control-Allow-Origin' header is present on the requested Resource. Origin 'http://localhost:8080' is therefore not allowed access. The Response had HTTP status code 405.
I know it’s CORS I tried to put this code on the angle:
moduloVistoria.config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
}]);
But nothing works. My backend is in PHP and already put:
header("Access-Control-Allow-Origin: *");
Can someone tell me what might be going on ?
Have you enabled the API in the Google Developers Console? I suggest reading this document (in English): https://developers.google.com/maps/documentation/distancematrix/
– bfavaretto
pt_BR: https://developers.google.com/maps/documentation/distancematrix/? language=pt_BR
– bfavaretto
I did according to the document, but it still doesn’t work. The document doesn’t talk about Cors.
– Guilherme De Menezes Ferreira
Enabled on console, generated key, but same error continues.
– Guilherme De Menezes Ferreira
When enabled allow control allow in Chrome works
– Guilherme De Menezes Ferreira
Does anyone know what it can be ?
– Guilherme De Menezes Ferreira
Managed to solve the above problem? Could post the solution? Grateful!
– Allan Andrade