159

We're trying to develop an geoplacement app for one of our clients, and we want first to test it in out own domain.

We have signed for Google Maps JavaScript API, and we have a valid browser key and our domain, www.grupocamaleon.com, has been authorized to use that key.

But we can't make even the easiest example to run without error.

We have, in our domain and with our key, the following demo:

(1) http://www.grupocamaleon.com/boceto/aerial-simple.html

But it doesn't work, and Firebug console says:

"Google Maps API error: Google Maps API error: RefererNotAllowedMapError (link to Google documentation on RefererNotAllowedMapError) Your site URL to be authorized: (1)"

My credential page is missing the possibility of adding referrers to accept, so solutions involving adding referrers are not possible right now.

My credential Page:

enter image description here

Why do we get that error? How can we fix it?

geocodezip
  • 158,664
  • 13
  • 220
  • 245
  • Possible duplicate of [Google maps API referrer not allowed](http://stackoverflow.com/questions/32600314/google-maps-api-referrer-not-allowed). [Your code works for me](http://www.geocodezip.com/v3_SO_45degreeImagery_KeyError.html) (with my key), so there is something wrong with your key, the allowed referrers, or the services enabled to use with it. – geocodezip Feb 10 '16 at 05:46
  • But I have not such possibility in my credentials page, as you can see in my answer here. Any hint? – Grupo Camaleón Creativos Feb 11 '16 at 13:24
  • Well, I'm a newbie and I don't know how to use this site corrently yet. Sorry for the inconveniences. I've edited my question, adding information on my credential page. Some solutions cited involve adding referrers, what I can not do at the moment. – Grupo Camaleón Creativos Feb 12 '16 at 14:04
  • If you can't change the referrers for the key, remove it or replace it with one you control. A key is not required, but there are benefits to including one. – geocodezip Feb 12 '16 at 14:46
  • 1
    I created new key with no APP or API restrictions, it said expiredKey for 10 minutes, then started working. Next I tried adding just Places API, but it is being called from web and says: `Google Maps JavaScript API error: RefererNotAllowedMapError` even after waiting. Then I tried `Maps JavaScript API` and it kept saying `RefererNotAllowedMapError`, tried refreshing the page and it finally started to work after 2 minutes and 40 seconds. So watch the hell out. But WITHOUT anything DOES work for me, and so does `Maps JavaScript API` only. You just have to wait a lot. – psycho brm Oct 03 '18 at 00:22
  • Don't forget to **clear the browser cache** after making changes - this killed my time – Anand Rockzz Jun 09 '19 at 18:48
  • and **Note:** It may take up to **5 minutes** for settings to take effect – Anand Rockzz Jun 09 '19 at 20:17
  • Regenerating the key has worked for me. – rockneverdies Aug 18 '23 at 11:40

32 Answers32

211

I know this is an old question that already has several answers, but I had this same problem and for me the issue was that I followed the example provided on console.developers.google.com and entered my domains in the format *.domain.tld/*. This didn't work at all, and I tried adding all kinds of variations to this like domain.tld, domain.tld/*, *.domain.tld etc.

What solved it for me was adding the actual protocol too; http://domain.tld/* is the only one I need for it to work on my site. I guess I'll need to add https://domain.tld/* if I were to switch to HTTPS.

Update: Google have finally updated the placeholder to include http now:

Google Maps API referrer input field

powerbuoy
  • 12,460
  • 7
  • 48
  • 78
  • 1
    I confirm: the only combination that allowed me the use of the API was `http://www.---.com/*` – Marco Panichi Aug 04 '16 at 08:18
  • 11
    This answer is the only one that got my code working. I can confirm that the example that Google provides does not work. – Jargs Aug 12 '16 at 18:07
  • Why this question had not any answer marked as the "best answer"? Specially powerbuoy's one. – Mohammad Saberi Aug 21 '16 at 05:24
  • 1
    Thank you, @Google, for giving us false information. **http://----.com/*** is the correct format. – Michael Yaeger Sep 26 '16 at 18:30
  • 3
    If you have multiple sub domains you can do, http://*.example.com and https://*.example.com to cover all bases – tim.baker May 04 '17 at 14:23
  • 1
    Maybe Google updated that feature – for me it works without the protocol. I have `example.com/*` in the settings field, and it works from `https://example.com/map` – Andy May 08 '17 at 09:30
  • I can confirm, too: This in combination with domain.com/*/* finally got it working for me, too. – mtness Jan 03 '18 at 09:58
  • I'm trying to get my test environment working with the url http://test.localdomain:8000/. Nothing, literally nothing works. Not even removing any restriction works. I always get the `RefererNotAllowedMapError` error. Restricting to my local IP doesn't work either. I'm helpless. – karolyi Mar 30 '18 at 01:56
  • @karolyi did you try the answer above? Ie adding the protocol? Local domains always work fine for me. – powerbuoy Mar 31 '18 at 19:42
  • @powerbuoy yes I did. I tried every possible combination, nothing worked. hence, I created a bug in their issue system. – karolyi Apr 01 '18 at 21:19
  • my ionic mobile app has domain as ionic://app#/tabs. How would I include it in the restrictions. I tried many combinations but in vain. Ex: ionic://app#/tabs, httpionic://app#/tabs, httpsionic://app#/tabs, ionic://*, ionic://app#/*, httpionic://*, ...... – AUK4SO Apr 07 '19 at 01:33
  • `*.example/*` works. I set the wrong API restriction. I Used Places instead of Maps Javascript API for Autocomplete. – lala May 21 '19 at 17:17
  • So many years after, the only thing working for me is separate entries `http://example.com/*`, `http://www.example.com/*` etc. – Wtower Oct 05 '20 at 12:28
  • Even in 2022 this was much needed, thanks! – alib0ng0 Jan 24 '22 at 15:16
31

Come on Google, you guys are smarter than the API Credential page lets on. (I know because I have two sons working there.)

The list of "referrers" is far pickier than it lets on. (Of course, it should be more forgiving.) Here are some rules that took me hours to discover:

There are probably other rules, but this is a tedious guessing game.

Rick James
  • 135,179
  • 13
  • 127
  • 222
  • 1
    About the answer before the edit, I'm running out of patience too. Looks like that wildacards (*) only work in the end of an address (`http://my.site.com/*`) or in in a subdomain (`http://*.site.com`). In ALL the other cases it doesn't work – Christian Vincenzo Traina Dec 15 '18 at 18:15
  • 1
    I had incorrectly put a restriction to only allow the Places API (the tab right next to the referrer restrictions). This results in the same RefererNotAllowedMapError error. – Matt Greer Jan 21 '19 at 23:38
  • Adding www. to my domain name fixed it for me. I am not sure if adding a wildcard (*) to the end of domain, such as `(https://www.my-site.com/*)` has also corrected the issue. – Mugé Feb 12 '19 at 17:03
  • my ionic mobile app has domain as ionic://app#/tabs. How would I include it in the restrictions. I tried many combinations but in vain. Ex: ionic://app#/tabs, httpionic://app#/tabs, httpsionic://app#/tabs, ionic://*, ionic://app#/*, httpionic://*, ...... – AUK4SO Apr 07 '19 at 01:34
  • @AUK4SO - The pound sign (`#`) has a special meaning in urls. See ``. Or did you mean `iconic://1234/foo`? – Rick James Apr 09 '19 at 18:13
  • @RickJames - Yea, I mean my server url is ionic://app – AUK4SO Apr 09 '19 at 23:54
  • Moving my domain up in the list is what fixed it for me… Really, Google? – Xhynk May 06 '19 at 23:15
  • @AUK4SO - did you ever get this to work for the ionic app? I am using Javascript Map API in my app and am having a devil of a time figuring out the correct restriction url. The console error I am getting is: `Your site URL to be authorized: __file_url__//android_asset/www/index.html#/tab/map////` - thus what is my referrer url supposed to be? Is it `http://localhost/index.html` or `http://localhost/index.html#/tab/map/` or `file:///android_asset/www/index.html#/tab/map////` - I am stumped on this. – rolinger Aug 09 '19 at 18:44
  • @RickJames - any insight into my question for auk4so above? – rolinger Aug 09 '19 at 20:14
  • @rolinger Google treats http or https as valid protocols. I suggest you to check the "ionic-cordova-webview" plugin version. Go with the latest version >=4.0. https://github.com/ionic-team/cordova-plugin-ionic-webview – AUK4SO Aug 16 '19 at 04:13
26

Wildcards (asterisks) ARE NOT allowed in the subdomain part.

  • WRONG: *.example.com/*
  • RIGHT: example.com/*

Forget what Google says on the placeholder, it is not allowed.

Daniel Loureiro
  • 4,595
  • 34
  • 48
20

According to the documentation, 'RefererNotAllowedMapError' means

The current URL loading the Google Maps JavaScript API has not been added to the list of allowed referrers. Please check the referrer settings of your API key on the Google Developers Console.

I have the Google Maps Embed API set up for my own personal/work use and thus far have not specified any HTTP referrers. I register no errors. Your settings must be making Google think the URL you're visiting is not registered or allowed.

enter image description here

TRose
  • 1,718
  • 1
  • 16
  • 32
20

Just remind that if you just change it, it may take up to 5 minutes for settings to take effect.

Putu De
  • 309
  • 2
  • 3
16

I tried many referrer variations and waiting 5 minutes as well until I realized the example Google populates in the form field is flawed. They show:

*.example.com/*

However that only works if you have subdomain. or www. in front of your domain name. The following worked for me immediately (omitting the leading period from Google's example):

*example.com/*
ow3n
  • 5,974
  • 4
  • 53
  • 51
  • 11
    Bad idea - someone could create `hackexample.com` and use your api – HyderA Aug 09 '17 at 08:41
  • 3
    @HyderA - A more likely possibility is that someone would register a bunch free google accounts to get extra map loads. – ow3n Aug 09 '17 at 12:19
  • @HyderA they would still need the key, so not a huge chance. But you're right, still a potential risk. – Eoin Aug 02 '18 at 10:15
  • my ionic mobile app has domain as ionic://app#/tabs. How would I include it in the restrictions. I tried many combinations but in vain. Ex: ionic://app#/tabs, httpionic://app#/tabs, httpsionic://app#/tabs, ionic://*, ionic://app#/*, httpionic://*, ...... – AUK4SO Apr 07 '19 at 01:34
14

According the google docs this happened because the url on which you are using the Google Maps API, it not registered in list of allowed referrers

EDIT :

From Google Docs

All subdomains of a specified domain are also authorized.

If http://example.com is authorized, then http://www.example.com is also authorized. The reverse is not true: if http://www.example.com is authorized, http://example.com is not necessarily authorized

So,Please configure http://testdomain.com domain, then your http://www.testdomain.com will start work.

Community
  • 1
  • 1
RIYAJ KHAN
  • 15,032
  • 5
  • 31
  • 53
  • In my case it was misconfigured DNS for the domain. For example: www.testdomain.com worked fine testdomain.com didn't work causing an error – Trevor Jul 02 '16 at 19:09
  • 2
    It would seem the logic of that is reversed? Unless I am missing something. – twobob Jun 25 '17 at 22:06
11

Check you have the correct APIS enabled as well.

I tried all of the above, asterisks, domain tlds, forward slashes, backslashes and everything, even in the end only entering one url as a last hope.

All of this did not work and finally I realised that Google also requires that you specify now which API's you want to use (see screenshot)

enter image description here

I did not have ones I needed enabled (for me that was Maps JavaScript API)

Once I enabled it, all worked fine using:

http://www.example.com/*

I hope that helps someone! :)

David Robertson
  • 479
  • 7
  • 17
9

The Problem
Google suggests the format *.example.com/*
This format does not work.

The Solution
Check the browser console for the Google Maps JavaScript API error: RefererNotAllowedMapError
Underneath the error it should have: "Your site URL to be authorized: https://example.com/".
Use that url for the referrer and add a wildcard * to the end of it (https://example.com/*, in this case).

Darren Murphy
  • 1,076
  • 14
  • 12
8

I found that even your HTTP Referreres are valid enough, wrong set of API Restrictions causes Google Maps JavaScript API error: RefererNotAllowedMapError.

For example:

  • You are using Javascript API for the key.
  • Add http://localhost/* to Application Restrictions / HTTP Referrences
  • Choose Maps Embed API instead of Maps Javascript API
  • This causes RefererNotAllowedMapError
hiroshi
  • 6,871
  • 3
  • 46
  • 59
8

There are lots of supposed solutions accross several years, and some don’t work any longer and some never did, thus my up-to-date take working per end of July 2018.

Setup:

Google Maps JavaScript API has to work properly with…

  • multiple domains calling the API: example.com and example.net
  • arbitrary subdomains: user22656.example.com, etc.
  • both secure and standard HTTP protocols: http://www.example.com/ and https://example.net/
  • indefinite path structure (i.e. a large number of different URL paths)

Solution:

  • Actually using the pattern from the placeholder: <https (or) http>://*.example.com/*.
  • Not omitting the protocol, but adding two entries per domain (one per protocol).
  • An additional entry for subdomains (with a *. leading the hostname).
  • I had the feeling that the RefererNotAllowedMapError error still appeared using the proper configuration (and having waited ample time). I deleted the credential key, repeated the request (now getting InvalidKeyMapError), created new credentials (using the exact same setup), and it worked ever since.
  • Adding mere protocol and domain seemed not to have included subdomains.
  • For one of the domains, the working configuration looks like this:

Screenshot from Google API configuration

(As text:)

Accept requests from these HTTP referrers (web sites)
    https://*.example.com/*
    https://example.com/*
    http://*.example.com/*
    http://example.com/*
dakab
  • 5,379
  • 9
  • 43
  • 67
  • 1
    In my case, this solution helped but had API Restriction on the wrong API. For some reason, the same error message was returned. Changing API Restriction from 'Places API' to 'Maps Javascript API' fixed the issue. – LMG Aug 09 '18 at 14:55
  • deleting the key and creating a new one worked for me – Code-Apprentice Apr 23 '22 at 03:32
8

None of these fixes were working for me until I found out that RefererNotAllowedMapError can be caused by not having a billing account linked to the project. So make sure to activate your free trial or whatever.

Owen Masback
  • 420
  • 1
  • 4
  • 10
6

This is another sh1tty Google product with a terrible implemenation.

The problem I have found with this is that if you restrict an API key by IP address, it wont work... BUT far be it from Google to make this point clear... It wasn't until troubleshooting and researching I found:

API keys with an IP addresses restriction can only be used with web services that are intended for use from the server side (such as the Geocoding API and other Web Service APIs). Most of these web services have equivalent services within the Maps JavaScript API (for example, see the Geocoding Service). To use the Maps JavaScript API client side services, you will need to create a separate API key which can be secured with an HTTP referrers restriction (see Restricting an API key).

https://developers.google.com/maps/documentation/javascript/error-messages

FFS Google... Pretty important piece of information that would be good to clarify on setup...

php-b-grader
  • 3,191
  • 11
  • 42
  • 53
4

enter image description here

Accept requests from these HTTP referrers (web sites)

Write localhost directory path

flavio.donze
  • 7,432
  • 9
  • 58
  • 91
Ayan Chakraborty
  • 613
  • 1
  • 8
  • 13
  • 3
    according to Google's text it is supposed to be an optional property and if it blank it should work – ejectamenta Jun 25 '16 at 21:10
  • @ayanchakraborty - I have tried 10 different combinations of http://localhost/index.html (and various paths) as well as various combinations of file:///android_assets/www/index.html - but nothing is working. The RefererNotAllowedMapError in console is showing me: Your site URL to be authorized: __file_url__//android_asset/www/index.html#/tab/map////` - but this and variations don't work either. – rolinger Aug 10 '19 at 11:34
4

I experienced the same error:

enter image description here

This link talks about how to set up API key restrictions: https://cloud.google.com/docs/authentication/api-keys#adding_http_restrictions

In my case, the problem was that I was using this restriction:

HTTP referrers (web sites) Accept requests from these HTTP referrers (web sites) (Optional) Use *'s for wildcards. If you leave this blank, requests will be accepted from any referrer. Be sure to add referrers before using this key in production. https://*.example.net/*

This means that URLs such as https://www.example.net or https://m.example.net or https://www.example.net/San-salvador/ would work. However, URLs such as https://example.net or https://example.net or https://example.net/San-salvador/ would not work. I simply needed to add a second referrer:

https://example.net/*

That fixed the problem for me.

Jaime Montoya
  • 6,915
  • 14
  • 67
  • 103
4

I add 2 website domains, set "*" in subdomain is not working but specific subdomain "WWW" and non-subdomain have been worked for my websites using the same Google Map API key.

dont' use "*" in subdomain

Hope it help.

Pare
  • 41
  • 1
4
  1. That your billing is enabled

  2. That your website has been added to Google Console

  3. That your website is added to the referrers in your app.

  4. (do a wildcard for both www and none www)

http://www.example.com/* and http://example.com/*

  1. That Javascript Maps is enabled and you are using the correct credentials

  2. That the website has been added to your DNS to enable your Google Console above.

  3. Smile after it works!

Community
  • 1
  • 1
Morris
  • 91
  • 1
  • 2
  • 1
    Your list of allowed referrers can be found in Google Cloud Platform web console (console.cloud.google.com) under `APIs & Services > Credentials > (your key) > Application restrictions > HTTP Referrers` – Master of Ducks Jul 10 '19 at 13:07
4

Enable billing for Google project fixed the problem.

ahgood
  • 1,847
  • 20
  • 19
3

you show a screenshot of your api credentials page, but you have to click on "Browser key 1" and go from there to add referrers.

ITwrx
  • 114
  • 3
3

For deeper nested pages

If you have a project in a folder for example or nested pages

http://yourdomain.com/your-folder/your-page you can enter this in

http://yourdomain.com/*/*

The important part being /*/*/* depending how far you need to go

It seems that the * will not match / or get into deeper paths..

This will give your full domain access, well unless you have deeper nesting than that..

Radmation
  • 1,486
  • 1
  • 13
  • 30
3

I struggled to make this work as well, but here are some pointers:

  • The URLs set as referrers include http, e.g. http://example.com/*
  • Google Maps JavaScript API was enabled
  • Billing was set-up on this account

Once all of this above was resolved, the maps displayed as expected.

FMCorz
  • 2,586
  • 1
  • 21
  • 18
2

http://www.example.com/* has worked for me after days and days of trying.

Shingai Munyuki
  • 551
  • 1
  • 11
  • 25
2

I got mine working finally by using this tip from Google: (https://support.google.com/webmasters/answer/35179)

Here are our definitions of domain and site. These definitions are specific to Search Console verification:

http://example.com/ - A site (because it includes the http:// prefix)
example.com/ - A domain (because it doesn't include a protocol prefix)
puppies.example.com/ - A subdomain of example.com
http://example.com/petstore/ - A subdirectory of http://example.com site
1

I was attempting to use the Places API (Autocomplete) and had to also enable the Maps Javascript API from within Google Cloud Console before the Places API would work.

brad
  • 1,407
  • 19
  • 33
0

Check your declaration on site. To load the Google Maps JavaScript API, use a script tag like this

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"
async defer></script>

I using this declaration on my Wordpress site in function.php file

wp_enqueue_script("google-maps-v3", "//maps.google.com/maps/api/js?key=YOUR_API_KEY", false, array(), false, true);

I have set API key on this format, and its works fine

http://my-domain-name(without www).com/*

this declaration not working

*.my-domain-name.com/*
cigien
  • 57,834
  • 11
  • 73
  • 112
Nalaskow
  • 1
  • 1
0

Removing the restrictions (to None) worked for me.

Robot Boy
  • 1,856
  • 1
  • 17
  • 17
  • 6
    removing the restrictions is considered bad practice and makes your API vulnerable. – mtness Jan 03 '18 at 09:56
  • 2
    @mtness yes obviously but the poster has already tried it first without success. Unfortunately Google's documentation isn't any more helpful. Every answer here are bringing in new tips, it's almost like a guessing game... – James Wong Jul 26 '18 at 04:27
0

In my experience

http://www.example.com

worked fine But, https required /* at the end

RationalRabbit
  • 1,037
  • 13
  • 20
0

Chrome's Javascript console suggested I declare the entire page address in my HTTP referrer list, in this instance http://mywebsite.com/map.htm Even though the exact address is http://www.mywebsite.com/map.htm - I already had wildcard styles listed as suggested by others but this was the only way it would work for me.

KJB
  • 23
  • 5
0

This worked for me. There are 2 major categories of restrictions under api key settings:

  • Application restrictions
  • API restrictions

Application restrictions:

At the bottom in the Referrer section add your website url " http://www.grupocamaleon.com/boceto/aerial-simple.html " .There are example rules on the right hand side of the section based on various requirements.

Application restrictions

API restrictions:

Under API restrictions you have to explicitly select 'Maps Javascript API' from the dropdown list since our unique key will only be used for calling the Google maps API(probably) and save it as you can see in the below snap. I hope this works for you.....worked for me

enter image description here

Check your Script:

Also the issue may arise due to improper key feeding inside the script tag. It should be something like:

  <script async defer src="https://maps.googleapis.com/maps/api/jskey=YOUR_API_KEY&callback=initMap"
  type="text/javascript"></script>
Tahir77667
  • 2,290
  • 20
  • 16
0

If you are working on localhost then do not include http or https in the url.

Use "localhost" without protocols. I struggled for days and found it working.

nitin.k
  • 91
  • 6
0

Something no one else seems to have mentioned in here that may be important is also this:

Http referrers are case sensitive.

So say you have someone access https://www.example.com/webpage, and someone wrote a link to that page as https://www.example.com/Webpage, you need BOTH entries, otherwise one of them is not going to work (unless you URL-rewrite to remove caps, or replace /Webpage with /*, but in our case, we want to limit down to folders under a certain domain, so this is a pain in the butt).

I feel like this is a bit stupid. Yes, URLs can be case sensitive, but not to the point where you would restrict a folder if its in caps, but not if it's lowercase, right?

krokador
  • 39
  • 6
0

The most succinct answer I have found for this as of writing is to use *example.com/*

Jayden Lawson
  • 2,154
  • 2
  • 21
  • 24