【问题标题】:Loading a Google Map API into wordpress post将 Google Map API 加载到 wordpress 帖子中
【发布时间】:2014-05-20 12:55:56
【问题描述】:

我正在尝试将谷歌地图加载到帖子中。

在我加载的标题中:

    <script type="text/javascript" src="http://dev.ateo.dk/wp-content/themes/ateo/js/parking.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
    <script src="//maps.google.com/maps/api/js?sensor=true" type="text/javascript"></script>

在 wordpress 的帖子中我加载:

<div id="map_div"></div>

您可以在此处查看 .js:http://dev.ateo.dk/wp-content/themes/ateo/js/parking.js

地图根本不显示,所以我希望你们能帮我解决这个问题。

【问题讨论】:

  • 您必须最后包含您的 parking.js 脚本。

标签: javascript wordpress google-maps


【解决方案1】:

正如@Anto Jurković 在 cmets 中提到的,您最后需要包含您的 parking.js

当这些对象尚不存在时,您将初始化地图和其他对象,因为稍后会加载您的 jquery 和 Google 地图。此外,您在加载地图 javascript 时不提供 API 密钥,因此 Google 不会为您提供地图。

所以一定是这样的:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
<script src="//maps.google.com/maps/api/js?key=YOUR_API_KEY&sensor=true" type="text/javascript"></script>
<script type="text/javascript" src="http://dev.ateo.dk/wp-content/themes/ateo/js/parking.js"></script>

How you can get the API key 记录在 Google Maps v3 官方文档中。

TL;DR:您将通过 Google 开发者控制台获得它

【讨论】:

  • 我现在试过了,所以顺序和你描述的一样,但这没有任何区别。
  • 您的 googlemaps 中缺少 APIkey,它必须如下所示:&lt;script src="//maps.google.com/maps/api/js?key=YOUR_API_KEY&amp;sensor=true" type="text/javascript"&gt;&lt;/script&gt; 我会更新我的答案
【解决方案2】:

以上都不起作用。脚本什么时候加载没关系,脚本也应该用wordpress中的functions.php加载我发现的。

div 应该有一个 size 属性,这会导致地图被显示

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-27
    • 2011-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-15
    相关资源
    最近更新 更多