Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

I've noticed that whenever I was using the Google Maps API recently it was displaying an error in the JavaScript console and the API was not functional. This seems to be due to Google forcing developers to use an API Key whenever they access their Maps API now. This change is not huge and is easy to implement so read on.

This is the kind of error I was seeing...
 JavaScript Concole
Google Maps API error: MissingKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error


Google actually blogged about this change not long ago.
As of June 22, 2016 we are making the following changes to the Google Maps APIs Standard Plan:

* We no longer support keyless access (any request that doesn't include an API key). Future product updates are only available for requests made with an API key. API keys allow us to contact developers when required and help us identify misbehaving implementations.
...


Ok great, so you just have to get the key it seems! I noticed that requests for old URLs that have already accessed Maps API data worked, but any new URLs failed. In addition it looks like localhost access to the API doesn't work very well now, even when using a key.

So what you need to create is a browser key. Google has a page describing how to get the API key. If you click the 'Get a Key' button it will take you through the right steps.

First you will be asked to select a project or create a new one.

Then you're taken to the Credentials page where you can generate the key. It's a good idea to give this key a meaningful name as well as add a domain to restrict it to. If the key is unrestricted, other domains can make use of your key, which will reduce your quota allowances i.e. bad things will happen.
gmapsapikey1.png




After you click 'Create', your new API Key is presented to you.
gmapsapikey2.png


Making use of your key is easy...
 HTML
Old code like this...
<script src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>
Becomes...
<script src="https://maps.googleapis.com/maps/api/js?libraries=places&key=your_api_key_here"></script>


...simply replace 'your_api_key_here' with the actual value of your API Key.

As a bonus for any old URLs the 'no API key' warning will also disappear.

-i

A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.