Google Maps Module / Getting an API key for Google Maps

Introduction

API keys allow developers and site owners to track usage of Google’s services on their sites via Google’s APIs Console.

Most of Google’s free services are limited to a given number of views, page loads, etc. This means that when your site goes over those limits the services will stop working on your site.

By using an API key (coupled with “Automated Billing”) you can prevent any interruption due to usage: when you hit a given limit, Google will charge you for the extra usage while your site keeps working.

In the specific case of the Google Maps APIs, the limits are as follows:

  • 25,000 map views per day.
  • 2,500 geocoding requests per day.
  • 5 requests (of any kind) per second.

Why do I need API keys for the Google Maps module?

Most sites shouldn’t need API keys at all since limits on Google Maps APIs are very reasonable. Because limits are enforced during 24-hour intervals, even if your site goes over the limit, it could be the case that the outage lasts at most until the next day.

The Business Directory - Google Maps module uses a special kind of cache to prevent unnecessary API usage but sometimes that’s not enough. If, after enabling the module, some or all of your maps are not being displayed and you’ve been seeing a warning about failed requests on your WP backend for more than 24 hours, you definitely need an API key.

If your maps are not being displayed but you’re not seeing a warning on the backend, you probably don’t need an API key. Please double check your settings and, if the problem persists, contact us at businessdirectoryplugin.com for assistance.

Note (for sites on shared hosting)

When your site is on shared hosting, as the name suggests, it is sharing the same physical server resources (such as memory, CPU, etc.) with several other sites. Because all of those sites are on the same server, most of the time they’re also sharing the same IP address, regardless of the domain names being different.

Google enforces limits by looking at the IP address of your server so your site could be denied access to Google APIs even if it is not the one abusing the APIs or hitting the limits on its traffic alone.

An API key is a way to solve this issue without having to move your site to a dedicated server or VPS.

How do I get an API key from Google for use with the Google Maps module?

First, you’ll need a Google login, such as the one from a gmail.com account, and a credit card for billing.

  1. Visit Google Developers Console and enter your login information (if asked).
  2. If there are no projects listed, create a new one or select your current project.
  3. Go to “APIs & Auth → APIs” and make sure the following APIs are enabled:
    • Google Maps Geocoding API.
    • Google Maps JavaScript API v3.
  4. Go to “APIs & Auth → Credentials” and click “Create new Key”. Choose “Server key” as the key type. You can also add IP restrictions to your key (not recommended)
  5. Your new API key should be created. Take note of the API Key number (a long string of characters and numbers).
  6. (Optional) We suggest you set up automated billing for your project to avoid any outage. To do that, visit “Billing & settings” under your project’s name and click “Enable billing”.
  7. Log in to your site’s WP admin and visit “Directory Admin → Manage Options → Google Maps” to enter your new API Key.

References