【问题标题】:Google Maps JavaScript API warning: NoApiKeysGoogle Maps JavaScript API 警告:NoApiKeys
【发布时间】:2019-02-01 17:02:37
【问题描述】:

我们的网站给出警告提示“此页面无法正确加载 Google 地图”。 我正在使用 symfony2 的“象牙谷歌地图”包。 在控制台中,我们发现警告为“Google Maps JavaScript API 警告:NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys” 任何帮助将不胜感激。

【问题讨论】:

  • Google 需要 API 密钥才能调用 api。你必须向谷歌付费才能使用他们的 API。如果您只需要带有位置标记的交互式地图,则可以使用 iframe。

标签: javascript php jquery symfony google-maps


【解决方案1】:

正如错误消息所说,您需要 APIKey 来消除此错误。

您可以从https://developers.google.com/maps/documentation/javascript/get-api-key#get-an-api-key获取APIKey

然后将该密钥应用于您的代码,例如:

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

之后上述错误将不复存在!

【讨论】:

    【解决方案2】:

    如果您不想购买 API 密钥并且只需要静态地图,则可以使用 iFrame 来执行此操作。

    &lt;div class="mapouter"&gt;&lt;div class="gmap_canvas"&gt;&lt;iframe width="600" height="500" id="gmap_canvas" src="https://maps.google.com/maps?q=university%20of%20san%20francisco&amp;t=&amp;z=13&amp;ie=UTF8&amp;iwloc=&amp;output=embed" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"&gt;&lt;/iframe&gt;&lt;a href="https://www.pureblack.de"&gt;&lt;/a&gt;&lt;/div&gt;&lt;style&gt;.mapouter{text-align:right;height:500px;width:600px;}.gmap_canvas {overflow:hidden;background:none!important;height:200px;width:300px;}&lt;/style&gt;&lt;/div&gt;

    但我不知道这还能持续多久

    【讨论】:

      猜你喜欢
      • 2016-10-23
      • 2019-10-03
      • 2016-07-04
      • 2016-06-23
      • 1970-01-01
      • 2016-11-01
      • 1970-01-01
      • 2020-05-11
      相关资源
      最近更新 更多