我有一个应用程序的情况,我部署了一个可以显示在三个不同位置的谷歌地图:
因此,我需要用户在 api key 中添加一些引用者,以便在他们发布到自己的服务器时覆盖它们。
他们可以为他们自己的服务器上发布的 map 和本地浏览器中的预览添加一个引用者。
但是我不知道您在应用程序 Web View 中预览 map 时添加了什么作为引荐来源网址,并且此时页面的 url 是 file:///引用的 url?
如果我们将所有引用者留空以获得完整的通配符 api key ,它可以在应用程序的 web View 中工作。
对于 file:///url 的引用者,我已经尝试了尽可能多的配置,但没有运气:
我试过:
文件
文件*
文件/*
文件:///*
最佳答案
您似乎无法使用 file:///
解决此问题作为 URL 来源。你总会得到 RefererNotAllowedMapError错误。使用 file:///作为 URL 来源告诉我您正在尝试在本地环境中运行它。我建议您使用本地服务器,使用 Python Simple HTTP server或 NodeJS local server .
我在这个 SO thread 中列举了如何设置本地 Python 服务器的步骤。 .您将能够使用它来运行您的 Google map 示例。
更新
好消息,Google 增加了对 file:/referrers 的支持。您可以在文档中看到以下文本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
关于google-maps - 文件 :///的 Google Maps API key 引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38030031/