2017-09-23 37 views
0

規格:構建PhoneGap的應用程序沒有初始化谷歌地圖

  1. PhoneGap的桌面應用程式v0.4.3
  2. 的Android V5.1.1

上面的代碼與桌面應用做工精細,並config.xml由該PhoneGap桌面應用程序創建。 而當我在build.phonegap.com上試用它時,谷歌地圖未能初始化,所以沒有出現在Android上,只是一個白色屏幕。

這裏是我的initMap方法,它的API需要:

var map, directionsService, directionsDisplay; 

function initMap() { 

    directionsService = new google.maps.DirectionsService; 
    directionsDisplay = new google.maps.DirectionsRenderer; 

    map = new google.maps.Map(document.getElementById('gMap'), { 
     zoom: 10, 
     center: { lat: 25.0115052, lng: 66.7845126 }, 
     mapTypeId: 'roadmap', 
    }); 

    directionsDisplay.setMap(map); 


} // initMap() ends 

config.xml文件:

<?xml version='1.0' encoding='utf-8'?> 
<widget id="com.phonegap.helloworld" 
    version="1.0.0" 
    xmlns="http://www.w3.org/ns/widgets" 
    xmlns:gap="http://phonegap.com/ns/1.0"> 

    <name>TestApp</name> 
    <description> 
     A blank PhoneGap app. 
    </description> 
    <author email="[email protected]" href="http://phonegap.com"> 
     PhoneGap Team 
    </author> 
    <content src="index.html" /> 
    <access origin="*" /> 
</widget> 
+0

你準確得到了什麼錯誤? – henrisycip

+0

@henrisycip我認爲,我應該改造這個問題(一個簡單的應用程序,只顯示谷歌地圖沒有任何修改)。之後,我將編輯上述查詢。 –

回答

1

以下是這是必要的點要記住,而使得 本地 混合動力車應用程序:

  1. 目標設備(Android,IOS等)中對Web語言(HTML,CSS,JS等)的版本支持。
  2. 加載所需的插件/庫以使用本機組件。


解決方案:

你需要科爾多瓦 - 插件白名單插件來訪問地圖,那麼,這將解決你的問題:

<plugin name="cordova-plugin-whitelist" spec="1.3.2" /> 
<!-- Allow geo: links to open maps --> 
<allow-intent href="geo:*" /> 

Cordova Docs

默認情況下,不允許使用外部URL。在Android上,這等同於發送類型爲BROWSEABLE的意圖。

相關問題