【问题标题】:Using Google Map JavaScript library with cordova将 Google Map JavaScript 库与 cordova 一起使用
【发布时间】:2016-02-08 09:55:03
【问题描述】:

我正在尝试将 Google 地图 JavaScript API 与cordova 项目一起使用,

我正在获取地图,几秒钟后,我得到 RefererNotAllowedMapError for file:///android_asset/www/index.html

我也尝试在开发者控制台上提供此 URL,但没有成功。

我尝试提供通配符星号

有没有其他方法可以设置自定义引荐来源或如何解决这个问题?

---编辑---

我使用的是浏览器 API 密钥,我改为 Android API 密钥现在可以正常工作了。

cordova 的值错误: https://maps.googleapis.com/maps/api/js?key=<browser api key>

cordova 的正确值: https://maps.googleapis.com/maps/api/js?key=<android api key>

浏览器 API 密钥似乎只在 html 页面在 http url 上执行时才被允许

【问题讨论】:

  • 你必须为你的应用使用谷歌的 API 密钥 -> developers.google.com/maps/documentation/javascript/… 但最好不要在你的应用中使用 javascript api,使用原生插件。它要快得多。
  • 我正在使用 API 密钥
  • 您是否尝试过重新创建您的 API 密钥?
  • 您是否在 Google 开发者设置中添加了您的应用?
  • 我使用的是浏览器 API 密钥,我已更改为 Android API 密钥,现在它可以正常工作了。

标签: javascript cordova google-maps


【解决方案1】:

截至 2017 年 5 月,该问题已由 Google 解决。现在您可以使用带有 API 密钥的 file:/ 引荐来源网址。您可以在文档中看到以下文字

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

【讨论】:

    猜你喜欢
    • 2022-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-22
    • 2020-02-09
    • 2014-05-09
    • 2014-09-01
    • 2017-05-27
    相关资源
    最近更新 更多