2
votes

Looked everywhere — and have read dozens of other questions regarding Google APIs (Maps, Geocode, Places, Autocomplete, etc) — and nothing has worked.

I have an API key with Places, Static Maps, and Maps v3 & v2 services enabled.

I am trying to perform a reverse geocode (get street address information via JSON from lat/long coords).

Here is the URL I am passing in my JavaScript (last 5 digits of API key replaced with #####:

http://maps.googleapis.com/maps/api/geocode/json?latlng=49.8925136,-97.1466635&sensor=true&key=AIzaSyDbfv8bFidX1hSbXwwKTTxWQYgU7g####

The JSON response is:

{
    "results" : [],
    "status" : "REQUEST_DENIED"
}

As you can see, there is a "sensor=true" parameter being passed - which is the problem according to the Google Document supporting this API, but that is clearly not the case here.

I also tried passing simply

http://maps.googleapis.com/maps/api/geocode/json?latlng=49.8925136,-97.1466635&sensor=true

which returns expected JSON response when the URL is entered into the addressbar of a browser — but when added to the JavaScript in my HTML file, I again receive:

{
    "results" : [],
    "status" : "REQUEST_DENIED"
}

Any assistance is welcome, and greatly appreciated.

2
Why make things difficult with the spaces and invalid key? Only you can use your key, because you set the referrers in your Console. - Andrew Leach
The spaces are because I'm new and Stack doesn't allow more than one hyperlink for my questions (and it happens to auto-create hyperlinks for each URL I post...) - As for the API, preference only - and sharing the real one wouldn't assist in answering my question - as (you mention) it can only be used by a referring URL I specify. - mr.subtle
Yes of course: apologies. I've edited them in now you've confirmed there's no other reason not to have links! - Andrew Leach
No worries - I appreciate you taking the time to give some input. - mr.subtle

2 Answers

2
votes

Google don't particularly want you to use this static API in a web page. You should be using the Maps API in a web page, and its associated geocoding functionality (because you need to show the results on a map anyway). These static APIs are intended for use server-side, so it looks like they now refuse requests which come with an HTTP_REFERER header.

(Using the key server-side allows you to keep track of statistics, but an invalid key will always result in REQUEST_DENIED whether there is a referrer header or not.)

1
votes

I kept struggling with the exact same problem and I believe I came up with a very practical solution, which actually works just fine with me! You just have to make a small modification to your request query's URI. Instead of querying the

http://maps.googleapis.com/maps/api/geocode/json?latlng=49.8925136,-97.1466635&sensor=true

you should actually query the google maps api using the following URI:

http://maps.google.com/maps/api/geocode/json?latlng=49.8925136,-97.1466635&sensor=true

That small modification did the work for me like a charm!

Hope this helps.