Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google maps api, The provided API key is invalid

This is my first time posting a question on stack overflow, really hoping you guys can help.

I am trying to use the google maps geocodeing api for the first time and cannot get it to work.

The url format I am using is:

https://maps.googleapis.com/maps/api/geocode/json?address=LS2+9AQ&sensor=false&key=[MY_API_KEY]

In this case I am looking up the uk postcode: LS2 9AQ from a chrome browser.

The url does work when I don't use my api key but the limit on the number of allowed calls without the key is too low for my needs.

I am not yet using this in a production site, for now it is running from my local dev in chrome.

The actual response I get is:

[error_message] => The provided API key is invalid.
[results] => Array
    (
    )

    [status] => REQUEST_DENIED

When I remove the api key it works and returns the following:

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "LS2 9AQ",
               "short_name" : "LS2 9AQ",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "Woodhouse",
               "short_name" : "Woodhouse",
               "types" : [ "sublocality", "political" ]
            },
            {
               "long_name" : "Leeds",
               "short_name" : "Leeds",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "West Yorkshire",
               "short_name" : "West York",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "United Kingdom",
               "short_name" : "GB",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "Leeds",
               "short_name" : "Leeds",
               "types" : [ "postal_town" ]
            }
         ],
         "formatted_address" : "Woodhouse, Leeds, West Yorkshire LS2 9AQ, UK",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 53.8090296,
                  "lng" : -1.5509549
               },
               "southwest" : {
                  "lat" : 53.8083045,
                  "lng" : -1.5519655
               }
            },
            "location" : {
               "lat" : 53.808447,
               "lng" : -1.5517752
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 53.81001603029149,
                  "lng" : -1.550111219708498
               },
               "southwest" : {
                  "lat" : 53.80731806970849,
                  "lng" : -1.552809180291502
               }
            }
         },
         "types" : [ "postal_code" ]
      }
   ],
   "status" : "OK"
}

I have tried replacing the url with one that is currently in use on my works website and I got the same response, I have tried two different keys that I generated myself, one created last week and the other created an hour ago. I have set up the keys in the following way:

  • payment is enabled and a credit card is attached to the project (I was told this was needed to increase limit on api's by validating identity)
  • on one key referrer is set to "dev.test.com/*" (this is the url I am using on my local dev for this). On the other key no referrer is specified.
  • the key is a browser apps key

I am definitely entering the key properly, both me and another developer have checked this multiple times, does anyone have any ideas on what could be wrong?

Thanks in advance to anyone that helps.

UPDATE I have found the problem that was causing the process to stop working after 10 iterations. The google geocoding api has a limit of 10 calls per second in place and I was going over this, I have now added in a 1 second delay every 10 iterations and I can now in theory reach the daily limit.

However I still need more calls than the default free limit, as described in my comments below I believe I can use an api key to increase the free limit based on me having a verified account. I am using this for business but it is not high enough volume to be worth paying for it. Can anyone help clear this up for me?

like image 466
Colin McTaggart Avatar asked Nov 01 '13 12:11

Colin McTaggart


People also ask

Why is my google maps API key not working?

There are a several reasons why your google maps may not be working, the most common issue being no Google Map API key set or set incorrectly. To use the Google Maps JavaScript API, you must register your app project on the Google Cloud Platform Console and get a Google API key which you can add to your app.

How do I fix my API key is invalid?

You might encounter the following error: "There was an error! The API developer key is invalid." This means, that your API key is invalid. It has to be a Browser key. Try to generate it again, and restart Liferay once you've saved the new one.

What does API key invalid mean?

If you have registered your API key in EU domain(. eu) and configured API requests to US domain( .com), and vice versa, you will get "the API key is invalid" error. To resolve this issue, you need to send all your requests to the proper domain (US or EU).


1 Answers

Ok, It looks like what I was trying to do is impossible without paying for a business account. There is no way to apply an apikey to the google geocoding api.

I had misunderstood some documentation regarding the google maps api which referred to raising the allowed limit on daily queries.

This does not seem to apply to the geocoding api.

like image 183
Colin McTaggart Avatar answered Nov 15 '22 08:11

Colin McTaggart