问题
I'm trying to figure out why the following URL is returning:
<GeocodeResponse>
<status>INVALID_REQUEST</status>
</GeocodeResponse>
The URL I'm using is (API key taken out, for obvious reasons :))
https://maps.googleapis.com/maps/api/geocode/xml?key=xxxxx&address=Urb.%20Fundaci%F3n%20Mendoza%2C%204ta%20transversal%20D-25.%2CCumana%2C6101%2CVenezuela
I'm passing the address param... yet according to the documentation, it says that error is:
"INVALID_REQUEST" generally indicates that the query (address, components or latlng) is missing.
https://developers.google.com/maps/documentation/geocoding/
Any ideas? I'm at a bit of a loss!
EDIT: This is insane!
I added my own IP to the list of accepted ones for the API - and then access the URL from my browser:
https://maps.googleapis.com/maps/api/geocode/xml?address=Urb+Fundaci%C3%B3n+Mendoza,Cumana,6101,Venezuela&key=xxx
Then it works. However, accessing it via a simple script on the server (with the correct IP address also white-listed at google), and it gives me the { 'status' => 'INVALID_REQUEST' }
error... ARGH!!!!
回答1:
Ah man - talk about annoying. For anyone else coming across this problem - please make sure that any accents are URL Encoded - otherwise you will get this problem! In my Perl script I used URL::Encode, to convert any utf8 into encoded strings:
$url .= URL::Encode::url_encode_utf8($address);
That has now fixed it :)
回答2:
I saw the same error, but I realized that it was from a different source.
For anyone googling this later, be sure to make a GET request, not a POST request. This is why it worked in the browser for me with various different URL encodings but never worked in my app with the exact same parameters because I was always making POST requests in my app.
I added this as an answer because my problem matched all the symptoms described in the question, but it was not solved by OP's response.
来源:https://stackoverflow.com/questions/31218312/google-maps-geocoding-invalid-request