Fix ApiTargetBlockedMapError on Google Maps
Your key is valid and your domain is allowed. The key just isn't permitted to call the API that failed. That permission is a separate list on the key, called API restrictions, and the API your page needs is missing from it.
How to tell this is your problem
- The console shows ApiTargetBlockedMapError, often with the sentence “This API key is not authorized to use this service or API.”
- If the Maps JavaScript API itself is blocked, the whole map is grey with “Oops! Something went wrong.”
- If only a related service is blocked, the map draws normally but the address search, store locator, geocoding or directions fail. The error then appears only when someone uses that feature, for example after typing in the search box.
- Someone recently tightened the key's restrictions, created a new restricted key, or added a feature such as address autocomplete.
When a service such as Places is blocked, the console looks like this:
When the Maps JavaScript API itself is blocked, it reads:
The text before “error:” names the API that was blocked. That is the one you need to allow.
API restrictions vs application restrictions
Each API key has two independent sets of restrictions, and they answer different questions:
| Setting | What it controls | Error when it's wrong |
|---|---|---|
| Application restrictions (for a website, Websites) | Where the key can be used: which domains may send it | RefererNotAllowedMapError |
| API restrictions (Restrict key, then Select APIs) | What the key can be used for: which APIs it may call | ApiTargetBlockedMapError |
| Enabled APIs on the project (APIs & Services) | Whether the project can use the API at all | ApiNotActivatedMapError |
Google recommends using both kinds of restriction on every key, and that's good practice. The catch is that API restrictions are an allow-list. Once Restrict key is selected, every API the page calls must be ticked, and enabling an API on the project doesn't add it to the key's list.
Why it happens
- A Maps feature was added later. The key was restricted to the Maps JavaScript API, then someone added address autocomplete or a store locator. That needs Places API, which the key doesn't allow.
- The wrong Places API is ticked. Google lists separate entries. The newer Place class and the new Place Autocomplete widget need Places API (New). The legacy Places Service, Places library and older Autocomplete widget need Places API. Ticking one doesn't cover the other.
- JavaScript services each need their own API. The Geocoding service needs Geocoding API. The Directions service (Legacy) needs Directions API (Legacy). The Distance Matrix service (Legacy) needs Distance Matrix API (Legacy). The Elevation service needs Elevation API.
- A server key was reused. A key restricted to web service APIs, such as Geocoding only, was pasted into the website, where it also needs the Maps JavaScript API.
- Restrictions were tightened in a security clean-up. Someone restricted the key to the minimum after a leak and missed an API the site uses.
The fix, step by step
- 01Read the console line and note the API it names, for example “Places API” or “Google Maps JavaScript API”. If the error only shows up after interaction, use the search box or directions form with the console open.
- 02In Google Cloud Console open APIs & Services → Credentials in the project that owns the key, and select the key your page uses.
- 03Leave Application restrictions as they are. Scroll to API restrictions, which should show Restrict key selected.
- 04Open Select APIs and tick the API the console named. Always include the Maps JavaScript API for a website map, plus each service your page uses from the list above.
- 05If the API isn't in the list, it isn't enabled on the project. Enable it under APIs & Services → Library first, then come back. See ApiNotActivatedMapError.
- 06Select Save, wait a few minutes, then reload the page in a private window and use the feature that failed.
Switching API restrictions to Don't restrict key makes the error go away, and lets anyone who copies your key from the page source call every enabled API on your bill. Add the API you need to the list instead. If you suspect the key has already been copied, rotate it.
WordPress plugins and store locators
Store locator, directions and address-field plugins often use Places API and Geocoding API alongside the map. Check the plugin's documentation for the APIs it needs, and tick every one on the key. Some plugins also ask for a second, server-side key for geocoding. That key goes in a separate field, and it needs IP address restrictions, not website restrictions.
If you're moving off the legacy Places Autocomplete, the new widget needs Places API (New) on the key. See the Places migration guide.
Confirm it is fixed
Reload the page with the console open, then use every map feature: pan the map, type an address into the search box, request directions. No ApiTargetBlockedMapError should appear.
Run a scan too. As well as loading the page, the scanner types into address search boxes it finds, including ones inside iframes, so it catches errors that only fire when a visitor interacts with the page.
Common questions
I enabled the API in the project. Why is it still blocked?
Enabling an API on the project and allowing it on the key are separate settings. If the key's API restrictions are set to Restrict key, the API must also be ticked in the key's own list.
Which APIs does a Google Maps website key need?
Always the Maps JavaScript API. Add Places API or Places API (New) for address search, Geocoding API for address lookups, and the Directions or Routes APIs if you show directions. Only tick what the page actually uses.
Is ApiTargetBlockedMapError the same as RefererNotAllowedMapError?
No. RefererNotAllowedMapError comes from the key's application restrictions, meaning your domain isn't allowed. ApiTargetBlockedMapError comes from the key's API restrictions, meaning the API isn't allowed.
Why does the map work but the search box doesn't?
The key allows the Maps JavaScript API but not Places API. The map loads, and the error only fires when someone types into the search box and the page calls Places.
A scan tells you in about twelve seconds, from a clean session.