我在 phonegap leason 才大约两个月。我一直在 google ripple 模拟器中测试该应用程序,并且在 google map 上一切正常。
但是,当我将此项目上传到 phonegap build 并将其安装到我的 Android 设备时,google map 没有显示。
这是我的index.html
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
<script src="lib/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<link href="css/all.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" charset="utf-8">
window._cordovaNative = true;
</script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady()
{
//navigator.geolocation.getCurrentPosition(onSuccess, onError);
var map = new GoogleMaped();
map.initialize();
}
function GoogleMaped()
{
this.initialize = function(){
var map = showMap();
}
var showMap = function(){
var mapOptions =
{
zoom: 4,
center: new google.maps.LatLng(55.689403, 12.521281),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
return map;
}
}
$(document).ready(function(){
alert("hi al");
});
</script>
</head>
<body>
<div id="phonegapWrapper" style="">
<div id="map_canvas">
</div>
</div>
<script type="text/javascript" src="phonegap.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>
这是我的config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "com.empatix.app"
versionCode = "10"
version = "1.0.0" >
<plugin name="cordova-plugin-whitelist" />
<plugin name="com.indigoway.cordova.whitelist.whitelistplugin" spec="1.1.1" source="pgb" />
<!-- versionCode is optional and Android only -->
<feature name="http://api.phonegap.com/1.0/network"/>
<feature name="http://api.phonegap.com/1.0/device"/>
<feature name="http://api.phonegap.com/1.0/geolocation"/>
<feature name="http://api.phonegap.com/1.0/notification"/>
<access origin="*"/>
<access origin="http://google.com" />
<access origin="https://google.com" />
<access origin="http://maps.google.com" />
<access origin="http://maps.google.com/*" />
<access origin="http://*.google.com" />
<access origin="http://dev.hospitalku.com/*" />
<access origin="http://code.jquery.com/*" />
<access origin="https://maxcdn.bootstrapcdn.com/*" />
<access origin="https://maxcdn.bootstrapcdn.com/*" />
<access origin="*" />
<access origin="*.google.com"/>
<access origin="*.googleapis.com"/>
<access origin="*.gstatic.com"/>
<allow-navigation href="*" />
<allow-navigation href="http://*/*" />
<allow-navigation href="https://*/*" />
<allow-navigation href="data:*" />
<allow-intent href="geo:*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="*" />
<name>Empatix App</name>
<description>
An example for phonegap build docs.
</description>
<author href="https://dev.hospital.com" email="al_kasih@outlook.com">
Hardeep Shoker
</author>
<access origin="http://phonegap.com" subdomains="true" />
</widget>
我在 phonegap 调试服务中得到的唯一控制台消息是:
未找到 Content-Security-Policy 元标记。使用cordova-plugin-whitelist插件时请加一个
有人可以帮我解决这个问题吗?
非常感谢。
最佳答案
您必须在 index.html(标题部分)中添加这一行:
<meta http-equiv="Content-Security-Policy" content="default-src ...">
有关详细说明,请查看此文档:
https://github.com/apache/cordova-plugin-whitelist#content-security-policy
SO 上的帖子:"No Content-Security-Policy meta tag found." error in my phonegap application
关于android - 谷歌地图没有出现在 Phonegap Build 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35042446/