谷歌地图没有显示在phonegap应用程序中

时间:2013-10-28 14:24:14

标签: android google-maps cordova webview

我正在尝试使用以下代码在我的应用中显示谷歌地图

<!DOCTYPE HTML>

    

    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <script scr="jquery.js></script>
    <link rel="stylesheet" href="jquery.mobile-1.3.0.css" />
    <script type="text/javascript" src="cordova-2.4.0.js"></script>
    <script type="text/javascript" src="jquery.mobile-1.3.0.min.js"></script>

<style type="text/css">
    html, body, #map-canvas {
        margin: 0;
        padding: 0;
        height: 100%;
    }

</style>

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>

<script type="text/javascript">
    function initialize() {
        var mapOptions = {
            center: new google.maps.LatLng(-34.397, 150.644),
            zoom: 8,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map-canvas"),
                                      mapOptions);
    }
    google.maps.event.addDomListener(window, 'load', initialize);
    </script>

    

当我的MainActivity.java像

时,它工作正常
import org.apache.cordova.DroidGap;
import android.os.Bundle;
import android.webkit.WebView;
public class MainActivity extends DroidGap {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);     
    setContentView(R.layout.activity_main);
    WebView myBrowser = (WebView)findViewById(R.id.mybrowser);
    myBrowser.loadUrl("file:///android_asset/www/index.html");
    myBrowser.getSettings().setJavaScriptEnabled(true);

}     }

但是当我使用

时,不显示谷歌地图
super.loadUrl("file:///android_asset/www/index.html");

他们有什么方法可以解决这个问题。提前谢谢。

1 个答案:

答案 0 :(得分:0)

尝试改变元

<meta http-equiv="Content-Security-Policy"
          content="default-src *;
               script-src 'self' 'unsafe-inline' 'unsafe-eval'
                           127.0.0.1:*
                           http://*.google.com
                           http://*.gstatic.com
                           http://*.googleapis.com
                           http://*.firebaseio.com
                           https://*.google.com
                           https://*.gstatic.com
                           https://*.googleapis.com
                           https://*.firebaseio.com
                           ;
               style-src  'self' 'unsafe-inline'
                          127.0.0.1
                           http://*.google.com
                           http://*.gstatic.com
                           http://*.googleapis.com
                           http://*.firebaseio.com
                           https://*.google.com
                           https://*.gstatic.com
                           https://*.googleapis.com
                           https://*.firebaseio.com
">

和Google脚本<script src="https://maps-api-ssl.google.com/maps/api/js?libraries=places"></script>