1
I am developing a system made in Silex/PHP and his frontend is being done in Angularjs, I have a method in it that I am wanting him to do a search in the Google Maps API to return me a certain route, but every time returns me the following error:
The header of the request:
If I enable Cors with the Chrome extension works perfectly:
I have an index.php where all requests go through it, so insert the following:
I’ve tried everything but nothing works, someone’s been through it ?
No use adding CORS headers to your website, the browser will check them at the API address, ie at the Google address, which you have no control over. What you need is to see the google API manual to see what is incorrect, but the little I’ve read already say that the use of Distance Matrix is prohibited by google for any use other than displaying the information on a google map.
– Leandro Godoy Rosa
But if I take the url and paste it into the browser it returns me the normal xml or json.
– Guilherme De Menezes Ferreira
This is because you opened the URL in the browser manually, by ajax is different, the browser blocks ajax requests between different domains unless it releases the access by CORS. And as I said, you should check the Google Apis manual, there you should find how to do it correctly, including acquiring an access key that Google uses to control access to its Apis and in which cases you may or may not use its Apis.
– Leandro Godoy Rosa
Leandro, OK. I’ll check here.
– Guilherme De Menezes Ferreira
Leandro could not yet, but only a doubt if I enable Chrome cross origin it works !
– Guilherme De Menezes Ferreira
Make no mistake, what this extension does is disable the browser security feature, it makes the browser work as if the server responded with CORS headers, this should never be used as a reference to create a program.
– Leandro Godoy Rosa