# Google Maps API keys

For any map geolocation, Enhanced Google Maps are needed (example: our Store Locator). These require an API key, and have a variable cost based on traffic to the page. Here is [Google's pricing for Enhanced Google Maps](https://cloud.google.com/maps-platform/pricing/sheet/).

The cost through Google Maps is variable, and will increase or decrease as traffic increases or decreases every month. To offset this, Google Maps provides a $200 credit per month to your account. Due to this credit, most customers have no or little cost from Enhanced Maps usage. If expected traffic can be provided to us, we can provide an estimate of the monthly Enhanced Maps cost.

## Creating your Google API keys

Using Enhanced Google Maps requires an API key. Here are instructions for setting this up:

* You can walk through the process to setup a Google Maps key here: <https://cloud.google.com/maps-platform/?apis=maps>
* You will need a existing google account/sign in
* You will click "Get started"
* You will create a project, setup a billing account, and then it should generate an API key for you (it will look something like `AIzaSyAa_ydj8A4mxymMDXXXXXXX`)
* You then send that Key over to us

### Enabling the Maps APIs

Under the access for your API key, you will want to make sure that the following APIs are enabled in the Google API console.

* Geocoding API
* Maps Javascript API
* Maps Static API
* Places API

### Enabling billing

For the keys to work, you will need to enable or connect a billing profile to the project under the Google API console.&#x20;

## Restricted access (optional)

We recommend that the API key not have any restrictions if it will be used on a number of different domains. However, if restrictions are desired for the key, you can follow these additional steps to accommodate.

1. In addition to your domains that you want to restrict the key to, `*.cloudbackend.net` and `localhost:8001` should be added to the allowable list
2. A second key should be setup that is unrestricted, and only has the Geocoding API enabled. It is necessary for this key with the Geocoding API to be unrestricted for the geolocation to function properly. This key will only be used on the backend and not publicly accessible.

## Debugging map errors

If there is problems with the display of Google Maps, you will see errors related to this on the maps themselves as well as in the browser console. You can use these console errors as a hint of what is wrong on how to resolve it.

![Example of a map error (location finder)](https://825756965-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L_zivnvKch6re2urR-L%2F-M_XiEKJvA6fd8n14CD8%2F-M_XifFioKpYE-QmGXjP%2FScreen%20Shot%202021-05-12%20at%203.31.33%20PM.png?alt=media\&token=b2a8ce42-c17d-4658-b48f-5592c5609297)

![Console error example](https://825756965-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L_zivnvKch6re2urR-L%2F-M_XiEKJvA6fd8n14CD8%2F-M_Xil5zJi4APLS02Sh0%2FScreen%20Shot%202021-05-12%20at%203.29.51%20PM.png?alt=media\&token=1510ae63-ad2c-49af-a320-3a67c3cb7de6)

### List of common errors:

| Error                       | Reason                                                                                                                        |
| --------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `BillingNotEnabledMapError` | This happens when billing (and adding a valid payment source) has not been completed on the Google API account.               |
| `RefererNotAllowedMapError` | Commonly happens on preview URLs. This means the API key was restricted and the current domain is not on the authorized list. |
| `ApiNotActivatedMapError`   | This happens if not all the required APIs were enabled for the API key                                                        |

A full list of Google Maps API errors can be found here:

{% embed url="<https://developers.google.com/maps/documentation/javascript/error-messages>" %}
