I have a situation with an application that I deploy a Google Map that can be displayed in three different locations:
So I need the user to have added some referrers to there api key to cover them for the time they publish to their own server.
They can add a referrer just fine for both the published map on their own server, and the preview in browser locally aspects.
But I can't figure out what you add as a referrer for the situation when the map is previewed in the applications web view, and the url for the page at that point is a file:/// referenced url?
If we leave all referrers blank for a complete wildcard api key it works in the webview in app.
I have tried about as many configurations as I can think of for a referrer for file:/// url but no luck:
I tried:
file
file*
file/*
file:///*
It seems that you won't be able to resolve this problem using file:///
as URL origin. You'll always get the RefererNotAllowedMapError error. Using file:/// as URL origin tells me you're trying to run this on a local environment. I suggest you use a local server using either Python Simple HTTP server or NodeJS local server.
I've enumerated the steps on how to setup a local Python server in this SO thread. You'll be able to run your Google Map sample using that.
UPDATE
Good news, Google has added support for file:/ referrers. You can see the following text in the documentation
file:// referers need a special representation to be added to the Key restriction. The "file:/" part should be replaced with "__file_url__" before being added to the Key restriction. For example, "file://path/to/" should be formatted as "__file_url__/path/to/*". After enabling file:// referers, it is recommended you regularly check your usage, to make sure it matches your expectations
https://developers.google.com/maps/documentation/javascript/get-api-key#key-restrictions
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With