请求修复Google Maps API的RefererNotAllowedMapError报错问题
Hey David, let's work through this frustrating RefererNotAllowedMapError you're hitting—even after configuring your Google Cloud Console to allow all domains, the error persists. Here are targeted checks and fixes to resolve this:
Common Causes & Fixes
Verify your wildcard referer format
Double-check your HTTP referrers setting in the Google Cloud Console. The correct wildcard to allow all domains is just*—avoid adding extra prefixes likehttp://*orhttps://*unless you specifically want to restrict to those protocols. Sometimes a typo or incorrect wildcard pattern (like*.*) can cause the restriction to still apply.Clear caches (browser & API server)
Google's API servers might cache old referer restrictions even after you update them. Try these steps:- Clear your browser's cache, cookies, and site data for Google-related domains
- Restart your application server if you're running a local or hosted service
- As a last resort, generate a brand new API key in the console and replace your existing one—this bypasses any residual cache tied to the old key
Check the actual Referer header being sent
Browsers sometimes send unexpected referer values (like local file pathsfile://or specific port numbers). Use your browser's DevTools (F12 → Network tab) to inspect the Maps API request, then look for theRefererfield in the Request Headers. If you see a specific value (e.g.,file:///C:/your-project/index.html), add that exact pattern to your allowed referrers list (e.g.,file:///*for local files).Confirm API service is enabled
Make sure your API key has the Google Maps JavaScript API enabled in the Cloud Console. Even with correct referer settings, a disabled service can throw misleading errors. Navigate to the "APIs & Services" → "Enabled APIs & services" section to verify.Check for conflicting restrictions
If your API key has both IP restrictions and referer restrictions enabled, they might conflict. Ensure only referer restrictions are active (or that both are correctly configured for your use case).
Relevant Error Context
Per Google's official documentation:
The RefererNotAllowedMapError error indicates that the current URL loading the Google Maps JavaScript API has not been added to the list of allowed referrers in the Google Cloud Console.
Your screenshot confirms the error is directly tied to referer validation, so focusing on the above checks should get you sorted.
内容的提问来源于stack exchange,提问作者David

