Cors Api Google

Asked

Viewed 100 times

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/

  • pt_BR: https://developers.google.com/maps/documentation/distancematrix/? language=pt_BR

  • I did according to the document, but it still doesn’t work. The document doesn’t talk about Cors.

  • Enabled on console, generated key, but same error continues.

  • When enabled allow control allow in Chrome works

  • Does anyone know what it can be ?

  • Managed to solve the above problem? Could post the solution? Grateful!

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.