I'm accessing the Google API to get some geolocation.
The endpoint looks like this:
https://maps.googleapis.com/maps/api/geocode/xml?address=84100 ORANGE FR&key=apikey
If I open this link in Chrome browser, the API will return some data.
If I access it using file_gets_content or simplexml_load_file it returns "zero results".
After some testing I found that I could see the results on Chrome because the browser itself was set to Italian. If I set it to English it returns "zero results", same as PHP.
How to get the same results in PHP as in Chrome?
I actually found the problem here.
Basically, when I set Chrome to Italian, it probably rearranged the order of the parameters, returning different results.
The actual problem is with the address parameter, where the city comes before the zip code.
Also, adding the parameter &language=it might work for the same reason.
Therefore, the correct URL should be
https://maps.googleapis.com/maps/api/geocode/xml?address=ORANGE 84100 FR&key=apikey
I spent too much time debugging this issue.