2012-10-02 26 views
2

Iam試圖讓Android的Google-Map.api與Phonegap一起使用。但我無法弄清楚這個問題。到目前爲止我嘗試了一切。請檢查我的代碼。我沒有得到任何錯誤,我也包括jQueryMobile。對一個混亂的代碼抱歉。Android:Google-Map無法使用Phonegap

的Index.html: - 包括所有種類的stuff-

google.html您的:

<body> 
<div data-role="page" id="foo" data-theme="c"> 
    <div data-role="content"> 
     <div id="map_canvas"></div> 
    </div> 
</div> 
<script type="text/javascript" src="googlemap.js"></script> 
<script type="text/javascript"> 
    function onDeviceReady() { 
     var map = new GoogleMap(); 
     map.initialize(); 
    } 
</script> 

googlemap.js是看到本教程中的一樣: christianengvall.se

的錨定Google.html的超文本引用包含ref =「external」attribut。我不知道它是否重要。

我還添加白名單在res/XML/cordova.xml(UP-2-日期?)

我的manifest文件具有所有權限的Android可能有。 (暫時)

當我在真實設備(Samsung Galaxy S3)上運行/調試此頁面時,出現白屏。

可能的問題可能是Google.html的數據角色屬性。也許有像data-role =「mapload」這樣的東西。

如果您需要更多信息,請詢問我。

//編輯

它仍然不起作用。我發現了另一個解決方案,儘管這是一個大混亂。如果有人能上傳好代碼,請去爲它

回答

2

您的代碼應該罰款也就是說,如果你有正確的CSS,禁用腳本,並添加CSS文件:

#map_canvas {background: red;} 

你看到紅色方塊嗎?如果不是,那麼給它一個高度,height: 100%是一個很好的高度在jquerymobile,如果你不使用頁腳,因爲它流動的內容(標題是確定)。如果你使用一個腳註,想100%的高度,順應$("#map_content").css("height", ($("*[data-rel=content]").height()-$("*[data-rel=footer]").height())+"px");

其他一些指針:

如果您有任何問題,請嘗試adb logcat(有Eclipse的一個窗口爲如果你不喜歡的終端),它可以給你一些指示。

據我所知,屬性rel=external是無關緊要的。

我現在用的白名單是:

<access origin="http://127.0.0.1*"/> <!-- allow local pages --> 

<access origin="http://google.com" subdomains="true"/> 
<access origin="http://gstatic.com" subdomains="true"/> 
<access origin="https://google.com" subdomains="true"/> 
<access origin="https://gstatic.com" subdomains="true"/> 
+0

我有同樣的問題,但我看到紅色框,我需要做什麼? – Furlan

0

另一個可能的問題:你複製

function onBodyLoad(){  
    document.addEventListener("deviceready", onDeviceReady, false); 
} 

the example

+0

如果這不起作用,請將其添加到「pageload」事件中。 –