且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Ionic Framework/Cordova 上的 Google 地图不适用于 android 构建

更新时间:2022-12-28 19:58:50

错误指出 google 未定义.我最有根据的猜测是 index.html 中的脚本没有正确加载:

Error states that google is undefined. My best educated guess would be that the script from the index.html is not loaded correctly:

<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyD4bzp0Ck8nTXgfs9ZYo8vXZ2tgWhqzWmY&sensor=true">

我认为这是因为使用了新的 Cordova 5.0 版本.您需要安装 cordova-plugin-whitelist 如下:

I think this is because of the new Cordova 5.0 release being used. You need to install the cordova-plugin-whitelist as following:

cordova plugin add cordova-plugin-whitelist

同时将以下内容添加到 config.xml:

Also add the following to config.xml:

<access origin="*" />
<allow-navigation href="*" />
<allow-intent href="*" />

最后将以下内容添加到您的 index.html:

Finally add the following to your index.html:

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

请注意,以上设置不是您希望在生产环境中使用的设置.请查看cordova-plugin-whitelistREADME/code> 了解更多.

Be aware that above settings are not settings you want to have in a production environment. Please take a look at the README of the cordova-plugin-whitelist to learn more.