2013-10-28 93 views
0

我嘗試使用下面的代碼谷歌地圖在PhoneGap的應用程序沒有顯示

<!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"); 

是他們的任何方式來解決這個問題。提前致謝。

+0

你設置訪問起源*上的config.xml –

+0

@AmitPrajapati我試圖起源*,但我得到「不能打電話方法appendchild null「錯誤。我也嘗試過「」但沒用,沒有錯誤,地圖也不顯示 – aaviss

+0

add deviceReady() google.maps.event.addDomListener(窗口,'load',初始化);在成功 –

回答

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 
"> 

和谷歌的腳本<script src="https://maps-api-ssl.google.com/maps/api/js?libraries=places"></script>

相關問題