Fix ExpiredKeyMapError on Google Maps
Your page sent an API key, and Google's systems won't accept it. Google's description covers two quite different situations: a key that has expired, and a key the system doesn't recognise yet. The first needs a replacement key. The second only needs a few minutes.
How to tell this is your problem
- The map loads grey with the “Oops! Something went wrong.” overlay.
- The console names ExpiredKeyMapError, not InvalidKeyMapError.
- Either you created or swapped in a key in the last few minutes, or the key is old and nobody has touched it in a long time.
This is what the console shows:
Why it happens
Google's error reference says the API key in the loader “has expired or is not recognized by the system”. It also notes that a newly created key may not be recognised straight away, and suggests waiting a few minutes before you try again. Beyond that, Google doesn't publish a list of reasons a key stops being accepted, so treat this as two cases:
- The key is brand new. You created it, or pasted it into the site, moments ago. Google's systems haven't caught up. This clears on its own.
- The key is no longer accepted. The key on the page has been around for a while and Google has stopped honouring it. The fix is a new key with the same restrictions.
Two related errors look similar. If the key doesn't exist at all, for example because it was deleted, Google usually reports InvalidKeyMapError. If the key exists but the Cloud project behind it can't be found, you'll see DeletedApiProjectMapError or ApiProjectMapError. Read the exact code in the console before you change anything.
The fix, step by step
Start by ruling out the brand-new key case:
- 01If you created or changed the key in the last few minutes, wait about five minutes and reload the page in a private window. If the map loads, you're done.
- 02If it still fails, open the page source, search for maps/api/js, and copy the key= value. Make sure it's the key you think it is, not an old one still served from a page or CDN cache.
If the key is old, or still fails after waiting, replace it:
- 01In Google Cloud Console open APIs & Services → Credentials in the project you use for Maps. Find the key your page uses and open it.
- 02Write down its settings: the application restriction type (usually Websites), every website entry, and every API listed under API restrictions.
- 03Create a new API key in the same project. Apply the same website restrictions and the same API restrictions before you use it. At minimum it needs the Maps JavaScript API, plus any others your page calls, such as Places API or Geocoding API.
- 04Put the new key into your site: the theme or plugin setting, page builder widget, or build configuration. Search for every place the old key appears, because a second copy left behind will keep failing.
- 05Clear your page, optimisation plugin and CDN caches, then load the page in a private window.
- 06Once the new key has worked for a day or two and nothing else is using the old one, delete the old key. Deleted keys can be restored for 30 days, so you have a safety net if something you missed breaks.
A browser key is visible to anyone who views your page source. Without website and API restrictions, someone else can use it on their site and the usage lands on your bill. If you think the old key was copied, follow the leaked key rotation guide and cap your Maps spend.
Where the key lives
Replacing the key in Cloud Console does nothing until every copy on your site is updated. Common places:
- WordPress: theme options, a maps or store locator plugin, a page builder's global integrations screen, and individual map widgets. See where page builders store the key.
- Your own code: an environment variable in your hosting provider, a config file, or a hard-coded string in a template. Check production and preview environments separately.
- Hosted platforms: some site builders take your own key in a settings field. Others manage the key themselves, in which case you need their support team. See platform map blocks.
If you load the API in your own code, keep the key in configuration so a replacement is a one-line change:
(g=>{/* Google's inline bootstrap loader, copied unchanged from the docs */})({
key: process.env.MAPS_BROWSER_KEY,
v: "weekly",
});
Confirm it is fixed
Reload the page in a private window with the console open. ExpiredKeyMapError should be gone and the tiles should load. If a new error appears, such as RefererNotAllowedMapError, the new key is being accepted and its restrictions need a tweak. That's the next step, and it means the key itself is now fine.
Run a scan as well. It loads the page with no cache and reports the key each Maps request used, so you can confirm no old copy is still being served.
Common questions
Do Google Maps API keys expire?
Google doesn't document a fixed lifetime for Maps API keys, and most keys keep working until someone deletes or replaces them. ExpiredKeyMapError is the error Google uses when it no longer accepts a key, or doesn't recognise a new one yet.
I just created the key. Why does it say expired?
Google notes that a newly created key may not be recognised straight away. Wait a few minutes, make sure the page isn't serving an old cached copy, and reload.
Can I renew or reactivate an expired key?
There is no renew option. Create a new key in the same project, copy the old key's restrictions onto it, and replace the key on your site.
Will a new key cost more or reset my free usage?
No. Usage and billing belong to the Cloud project, not the key, so a new key in the same project shares the same billing account and usage.
A scan tells you in about twelve seconds, from a clean session.