【问题标题】:Phonegap Build: Whitelisting Google Map Domains for API v3Phonegap 构建:将 API v3 的 Google 地图域列入白名单
【发布时间】:2013-10-23 05:36:50
【问题描述】:

我在让地图在两部真正的 Android 手机上正确显示时遇到了一些问题——一部运行 2.2.2,一部运行 4.2.2。后者在谈到地图时总是让我有些悲伤。我已经把它放在另一个线程here 中,因为我已经部分解决了。

注意:我正在使用带有 Dreamweaver CS6 的 Phonegap Build。只是一个没有清单 xml 文件的 config.xml。

现在我有另一个问题,我必须将所有域列入白名单,以便地图在 4.2.2 上正常运行,但我不知道为什么。 最初我在我的 config.xml 中有这个:

<access origin="*.googleapis.com" />
<access origin="*.gstatic.com" />
<access origin="*.google.com" />
<access origin="maps.googleapis.com" />
<access origin="maps.gstatic.com" />
<access origin="mt0.googleapis.com" />
<access origin="mt1.googleapis.com" />
<access origin="csi.gstatic.com" />

虽然这适用于 Android 2.2.2,但我会在 4.2.2 上遇到以下问题:

  • 地图底部缺少最后一行图块(如果我对 google maps src 使用 HTTPS)
  • 标记根本不会显示

只需将所有内容都列入白名单,所有这些问题都消失了。但是我不想将所有内容都列入白名单,所以有人知道我是否在这里遗漏了什么吗?

非常感谢任何帮助。

编辑:我知道,通过使用 *.googleapis.com,我还将包含其余类似的白名单域。但是,我在搜索中多次注意到 iOS 要求明确列出域。虽然目前这可能不适用,但我确实打算在 iOS 上使用这个应用程序,所以我把它留在了(除非有人可以告诉我它完全没用而且不需要 ;-)。

////////更新1 ////////

在浏览 chrome 开发者工具上的网络标签后,我提取了谷歌地图访问的所有 URL。通过明确说明它们中的每一个,一切正常:

    <access origin="https://mts.googleapis.com" subdomains="true"/>
    <access origin="https://mts0.googleapis.com" subdomains="true"/>
    <access origin="https://mts1.googleapis.com" subdomains="true"/>
    <access origin="https://maps.googleapis.com" subdomains="true"/>
    <access origin="https://fonts.googleapis.com" subdomains="true"/>
    <access origin="https://maps.gstatic.com" subdomains="true"/>
    <access origin="https://csi.gstatic.com" subdomains="true"/>
    <access origin="https://themes.googleusercontent.com" subdomains="true"/>

这些可能会发生变化,所以如果我可以在每个域前面使用通配符 * 会很好,但这不起作用。我尝试了以下两种方法,没有成功

    <access origin="*.googleapis.com" subdomains="true"/>
    <access origin="*.gstatic.com" subdomains="true"/>
    <access origin="*.googleusercontent.com" subdomains="true"/>


    <access origin="https://*.googleapis.com" subdomains="true"/>
    <access origin="https://*.gstatic.com" subdomains="true"/>
    <access origin="https://*.googleusercontent.com" subdomains="true"/>

有人知道为什么我在这些情况下无法使用通配符吗? 干杯。

////////更新 2/答案////////

经过大量实验,我找到了答案。看起来您必须非常具体地在 config.xml 中编写标签,尤其是在允许子域时 - 显然指定子域不适用于通配符,因此您需要两个标签块。我终于让两个设备都使用 https 正常工作了:

    <access origin="*.google.com" />
    <access origin="*.googleapis.com" />
    <access origin="*.gstatic.com" />
    <access origin="*.googleusercontent.com" />
    <access origin="google.com" subdomains="true"/>
    <access origin="googleapis.com" subdomains="true"/>
    <access origin="gstatic.com" subdomains="true"/>
    <access origin="googleusercontent.com" subdomains="true"/>

希望这对某人有用。我仍然不明白为什么它在旧版本的 Android 上运行良好。如果他们有这样的感觉,也许有人可以帮助启发我?

【问题讨论】:

    标签: android google-maps-api-3 cordova whitelist


    【解决方案1】:

    将域列入白名单的语法随着 PhoneGap 的版本而改变。如果您使用的是 3.1 或更高版本,请参阅此文档以了解语法:http://docs.phonegap.com/en/3.1.0/guide_appdev_whitelist_index.md.html。我想这可能是你的通配符不适合你的原因。

    我正在使用以下内容,它可以在我的 PhoneGap 应用中显示我的 Google 地图:

    <access origin="*://*.googleapis.com/*" subdomains="true" />
    <access origin="*://*.gstatic.com/*" subdomains="true" />
    <access origin="*://*.google.com/*" subdomains="true" />
    <access origin="*://*.googleusercontent.com/*" subdomains="true" />
    

    【讨论】:

      猜你喜欢
      • 2013-10-19
      • 1970-01-01
      • 1970-01-01
      • 2013-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多