【问题标题】:Cordova Google Map appears in lower version 4.1.2 Android phone but not in latest version Lollipop why?Cordova Google Map 出现在低版本 4.1.2 的 Android 手机中,但在最新版本的 Lollipop 中没有出现,为什么?
【发布时间】:2016-02-16 07:21:43
【问题描述】:

应用在低版本安卓手机上运行良好(在 jellybean 上测试)。它在低版本 (4.1.2) 安卓手机上显示谷歌地图。

我调用 Google 地图 API 的脚本是

<script src="https://maps.googleapis.com/maps/api/js?key=xxxxx"> </script>

在 config.xml 中

授予的权限列表

 <access origin="*" />
    <allow-navigation href="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>

在AndroidManifest.xml manifest下

<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <application android:hardwareAccelerated="true" android:icon="@drawable/logo" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="22" />

index.js

 map = new google.maps.Map(document.getElementById("mapmake"), myOptions);

HTML 元标记

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *"> 
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">

那么为什么它不能在最新的 Android Phone(5.1.1) 上显示 BLANK div?

【问题讨论】:

  • 您可以尝试使用没有api密钥的googlemap api v3并检查它是否工作。
  • 它不适用于此 Google 地图 API URL
  • 我也在最新版本中收到“google is undefined”错误。
  • 一件事而不是 https 使用 http... 如果不起作用,请查看 stackoverflow.com/questions/20386782/…

标签: android cordova google-maps


【解决方案1】:

所以以下这些更改可以在我的地图上工作

1.将您的 MAP 脚本链接更改为以下路径(MAP API v=3)

<script type='text/javascript' src='https://maps-api-ssl.google.com/maps/api/js?v=3.3&sensor=false'></script>

OR(如果您想嵌入其他库我的例子:('places'))

<script type='text/javascript' src='https://maps-api-ssl.google.com/maps/api/js?v=3.3&sensor=false&libraries=places'></script>

注意:(之后的脚本链接 jquery.min.jsindex.js 然后 把这个地图脚本链接)

2您有时可能会遇到以下错误

[拒绝加载脚本'maps.googleapis.com/maps/api/...;因为它违反了以下内容安全策略指令:“default-src 'self' data: gap: ssl.gstatic.com 'unsafe-eval'”。请注意,'script-src' 没有显式设置,因此 'default-src' 用作后备。]

为此更改元 http-equiv="Content-Security-Policy"

来自

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' http://* 'unsafe-inline'; script-src 'self' https://* 'unsafe-inline' 'unsafe-eval'" />

其余的都一样。谢谢。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-24
    • 1970-01-01
    • 1970-01-01
    • 2015-09-30
    • 1970-01-01
    相关资源
    最近更新 更多