Phonegap Android Geolocation示例不起作用

时间:2012-07-17 08:10:43

标签: android cordova geolocation

我尝试使用android 4.0.4和Phonegap 1.9的地理定位。我尝试了http://docs.phonegap.com/en/1.9.0/cordova_geolocation_geolocation.md.html#Geolocation

的第一个例子

我在AndroidManifest.xml和plugins.xml中添加了这些行。我启用了GPS和谷歌地图的工作。但是,当我在我的galaxy nexus上使用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,但我的Galaxy Nexus上的android 4.0.4上没有firefox beta或chrome。它不能作为Phonegap的android包而不是普通的html5页面。使用IPhone4S它正在工作!

如果您有任何想法是什么问题,请告诉我们!

谢谢!

1 个答案:

答案 0 :(得分:0)

尝试使用Google Api SDK!例如2.3.3 / 10版本。