2012-07-17 76 views
2

我嘗試使用android 4.0.4和Phonegap 1.9的地理位置。我嘗試了第一個例子http://docs.phonegap.com/en/1.9.0/cordova_geolocation_geolocation.md.html#GeolocationPhonegap Android地理位置示例不起作用

我在AndroidManifest.xml和plugins.xml中添加了行。我啓用GPS和谷歌地圖的工作。但是當我使用Phonegap啓動html文件時,它會顯示:「查找地理位置......」並且什麼都不做。

那是完整的logcat輸出:

07-17 10:13:08.296: D/CordovaWebView(7612): >>> loadUrlNow() 
07-17 10:13:18.984: D/CordovaWebView(7612): >>> loadUrlNow() 
07-17 10:13:19.132: D/OpenGLRenderer(7612): Flushing caches (mode 0) 
07-17 10:13:19.179: D/OpenGLRenderer(7612): Flushing caches (mode 1) 
07-17 10:13:33.984: I/CordovaLog(7800): Changing log level to DEBUG(3) 
07-17 10:13:33.984: I/CordovaLog(7800): Found preference for useBrowserHistory=false 
07-17 10:13:33.984: D/CordovaLog(7800): Found preference for useBrowserHistory=false 
07-17 10:13:33.984: D/DroidGap(7800): DroidGap.init() 
07-17 10:13:33.991: D/CordovaWebView(7800): >>> loadUrl  
(file:///android_asset/www/geolocation.html) 
07-17 10:13:33.991: D/PluginManager(7800): init() 
07-17 10:13:33.991: D/CordovaWebView(7800): >>> loadUrlNow() 
07-17 10:13:34.023: D/DroidGap(7800): onMessage(onPageStarted,file:///android_asset/www/geolocation.html) 
07-17 10:13:34.023: D/SoftKeyboardDetect(7800): Ignore this event 
07-17 10:13:34.046: D/libEGL(7800): loaded /system/lib/egl/libGLES_android.so 
07-17 10:13:34.046: D/libEGL(7800): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so 
07-17 10:13:34.054: D/libEGL(7800): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so 
07-17 10:13:34.070: D/libEGL(7800): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so 
07-17 10:13:34.140: D/dalvikvm(7800): GC_CONCURRENT freed 139K, 2% free 12959K/13191K, paused 3ms+2ms 
07-17 10:13:34.210: D/OpenGLRenderer(7800): Enabling debug mode 0 
07-17 10:13:34.210: D/SoftKeyboardDetect(7800): Ignore this event 
07-17 10:13:34.390: D/Cordova(7800): onPageFinished(file:///android_asset/www/geolocation.html) 
07-17 10:13:34.390: D/CordovaWebView(7800): >>> loadUrlNow() 
07-17 10:13:34.390: D/DroidGap(7800): onMessage(onNativeReady,null) 
07-17 10:13:34.390: D/DroidGap(7800): onMessage(onPageFinished,file:///android_asset/www/geolocation.html) 
07-17 10:13:34.398: I/SqliteDatabaseCpp(7800): sqlite returned: error code = 14, msg = cannot open file at line 27701 of [8609a15dfa], db=/data/data/de.xxxx.ble.html5/databases/webview.db 
07-17 10:13:34.398: I/SqliteDatabaseCpp(7800): sqlite returned: error code = 14, msg = os_unix.c: open() at line 27701 - "" errno=2 path=/CachedGeoposition.db, db=/data/data/de.xxxx.ble.html5/databases/webview.db 
07-17 10:13:34.413: D/DroidGap(7800): onMessage(networkconnection,3g) 
07-17 10:13:36.398: D/DroidGap(7800): onMessage(spinner,stop) 

它進入onDeviceReady()函數,但我認爲它不會調用的onSuccess也不onerror的。

那是我的代碼:

<!DOCTYPE html> 
    <html> 
    <head>  
    <title>Device Properties Example</title>  
    <script type="text/javascript" charset="utf-8" src="cordova-1.9.0.js"></script>  
    <script type="text/javascript" charset="utf-8">  

    // Wait for Cordova to load  
    document.addEventListener("deviceready", onDeviceReady, false);  

// Cordova is ready  
function onDeviceReady() { 
navigator.geolocation.getCurrentPosition(onSuccess, onError);  
} 

// onSuccess Geolocation   
function onSuccess(position) {   
var element = document.getElementById('geolocation'); 

element.innerHTML = 'Latitude: '   + position.coords.latitude     
      + '<br />' + 
        'Longitude: '   + 
      position.coords.longitude    + '<br />' + 
        'Altitude: '   + position.coords.altitude    + '<br />' + 
        'Accuracy: '   + position.coords.accuracy    + '<br />' + 
        'Altitude Accuracy: ' + position.coords.altitudeAccuracy  + '<br />' + 
        'Heading: '   + position.coords.heading    + '<br />' + 
        'Speed: '    + position.coords.speed     + '<br />' + 
        'Timestamp: '   + position.timestamp 
        + '<br />'; 


    }  


    // onError Callback receives a PositionError object  
     function onError(error) {   
alert('code: ' + error.code + '\n' +    
     'message: ' + error.message + '\n'); 
}  


    </script> 
    </head> 

    <body>  
<p id="geolocation">Finding geolocation...</p> 
    </body> 
    </html> 

更新:我剛剛發現我的代碼正在使用Internet Explorer 9,而在Firefox測試版或Chrome對我的Galaxy Nexus的Android 4.0.4。它不是用Phonegap作爲android程序包,而不是正常的html5頁面。隨着iPhone4S它的工作!

如果您有任何想法是什麼問題,請告訴我!

謝謝!

+0

更新:即使是地理定位的普通HTML5也不適用於我的Galaxy Nexus!我試過Firefox 14,Chrome 18和標準瀏覽器。但谷歌地圖正在工作!有人可以幫忙嗎? – fluxim 2012-07-17 11:14:15

回答

0

嘗試使用Google Api SDK!例如2.3.3/10版本。