google-maps - 文件 :///的 Google Maps API key 引用

标签 google-maps google-maps-api-3

我有一个应用程序的情况,我部署了一个可以显示在三个不同位置的谷歌地图:

  • 在应用程序 Webview
  • 浏览器预览
  • 发布到服务器

  • 因此,我需要用户在 api key 中添加一些引用者,以便在他们发布到自己的服务器时覆盖它们。

    他们可以为他们自己的服务器上发布的 map 和本地浏览器中的预览添加一个引用者。

    但是我不知道您在应用程序 Web View 中预览 map 时添加了什么作为引荐来源网址,并且此时页面的 url 是 file:///引用的 url?

    如果我们将所有引用者留空以获得完整的通配符 api key ,它可以在应用程序的 web View 中工作。

    对于 file:///url 的引用者,我已经尝试了尽可能多的配置,但没有运气:

    我试过:

    文件

    文件*

    文件/*

    文件:///*

    最佳答案

    您似乎无法使用 file:/// 解决此问题作为 URL 来源。你总会得到 RefererNotAllowedMapError错误。使用 file:///作为 URL 来源告诉我您正在尝试在本地环境中运行它。我建议您使用本地服务器,使用 Python Simple HTTP serverNodeJS 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/

    相关文章:

    google-maps - 在谷歌地图上加载 100-200K 标记

    android - Android 中的 StrictMode 策略违规 : StrictModeDiskReadViolation, WriteViolation

    javascript - 在 Bootstrap 模式上显示谷歌地图

    javascript - 使用 Firebase 更新谷歌地图上的特定标记

    ios - RestKit.ErrorDomain Code=-1011 对 Google 地理编码 API 请求的响应

    google-maps-api-3 - Google API key - 什么是服务器 key 和浏览器 key

    javascript - 将点击事件附加到 Google map

    javascript - 使用 jQuery 将 Google map 转换为静态图像以供下载

    javascript - 如何在谷歌地图上平移?

    javascript - 标签未添加到 Google map 标记