2012-07-17 40 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版本。