Cordova phonegap应用程序没有';行不通

Cordova phonegap应用程序没有';行不通,cordova,geolocation,Cordova,Geolocation,我是phonegap的新手。我正在创建一个应用程序来获取设备的位置…我已经用三星galaxy tab和htc进行了测试,但什么都没做…我尝试获取设备的速度,并将其显示在div-in屏幕上。这是我的代码: 地理位置: // Phonegap loads document.addEventListener("deviceready", onDeviceReady, false); var watchIDgeolocation = null; var watchID

我是phonegap的新手。我正在创建一个应用程序来获取设备的位置…我已经用三星galaxy tab和htc进行了测试,但什么都没做…我尝试获取设备的速度,并将其显示在div-in屏幕上。这是我的代码:

地理位置:

// Phonegap loads
    document.addEventListener("deviceready", onDeviceReady, false);
    var watchIDgeolocation = null;      
    var watchIDaccelerometer = null;    

// PhoneGap has loaded
    function onDeviceReady() {
        var options = { frequency: 1000 };  // I want obtain data each 1 s 
        watchIDgeolocation = navigator.geolocation.watchPosition(onSuccessGeolocation, onErrorGeolocation, options);
        startWatch(); 
    }

// Success
    var onSuccessGeolocation = function(position) {
        // These are functions that displays data in screen 
        cambioMarchas(position.coords.speed);       
        excesoVelocidad(position.coords.speed);     
        paradaProlongada(position.coords.speed);    
        aceleracionBrusca(position.coords.speed);   
        deceleracionBrusca(position.coords.speed);  
        accidenteDeTrafico(position.coords.speed);  


// ERROR
    function onErrorGeolocation(error) {
        alert('code: '    + error.code    + '\n' +
              'message: ' + error.message + '\n');
    }
我已经在Ripple上测试过了,它是Chrome的扩展,工作很好,改变了速度值,工作也很好……但对于这个设备,我不知道为什么不行。 为什么可以? 你好,丹尼尔


我读到可能需要在var选项中添加{enableHighAccurance:true}…但我不理解这一点…

好吧,丹尼尔,首先我建议你尝试一下这个常用的应用程序,测试设备是否可以使用,如果可以,它会用一条显示警报消息提醒你,同时,如果它工作正常,所以你的代码有问题,回去检查一下。给你:

// Global variable that will tell us whether PhoneGap is ready
   var isPhoneGapReady = false;
   function init() {
// Add an event listener for deviceready
   document.addEventListener("deviceready",
   onDeviceReady, false);
// Older versions of Blackberry < 5.0 don't support
// PhoneGap's custom events, so instead we need to perform
// an interval check every 500 milliseconds to see whether
// PhoneGap is ready. Once done, the interval will be
// cleared and normal processing can begin.
   intervalID = window.setInterval(function() {
   if (PhoneGap.available) {
    onDeviceReady();
           }
       }, 500);
   }

   function onDeviceReady() {
   window.clearInterval(intervalID);
// set to true
   isPhoneGapReady = true;

   alert('The device is now ready');
   }
// Set an onload handler to call the init function
   window.onload = init;
//将告诉我们PhoneGap是否准备就绪的全局变量
var isPhoneGapReady=false;
函数init(){
//为deviceready添加事件侦听器
文件。添加的文件列表(“deviceready”,
onDeviceReady,假);
//黑莓<5.0的旧版本不支持
//PhoneGap的自定义事件,因此我们需要执行
//每隔500毫秒进行一次间隔检查,以查看
//PhoneGap已准备就绪。完成后,间隔将为
//可以开始清除和正常处理。
intervalID=window.setInterval(函数(){
如果(PhoneGap.available){
ondevicerady();
}
}, 500);
}
函数ondevicerady(){
窗口。clearInterval(intervalID);
//设置为真
isPhoneGapReady=true;
警报(“设备现在已准备就绪”);
}
//设置一个onload处理程序来调用init函数
window.onload=init;

丹尼尔,首先,我建议你尝试一下这个常用的应用程序,测试设备是否可以使用,如果可以,它会用一条显示警告消息来提醒你,同时,如果它工作正常,那么你的代码有问题,所以回去检查一下。给你:

// Global variable that will tell us whether PhoneGap is ready
   var isPhoneGapReady = false;
   function init() {
// Add an event listener for deviceready
   document.addEventListener("deviceready",
   onDeviceReady, false);
// Older versions of Blackberry < 5.0 don't support
// PhoneGap's custom events, so instead we need to perform
// an interval check every 500 milliseconds to see whether
// PhoneGap is ready. Once done, the interval will be
// cleared and normal processing can begin.
   intervalID = window.setInterval(function() {
   if (PhoneGap.available) {
    onDeviceReady();
           }
       }, 500);
   }

   function onDeviceReady() {
   window.clearInterval(intervalID);
// set to true
   isPhoneGapReady = true;

   alert('The device is now ready');
   }
// Set an onload handler to call the init function
   window.onload = init;
//将告诉我们PhoneGap是否准备就绪的全局变量
var isPhoneGapReady=false;
函数init(){
//为deviceready添加事件侦听器
文件。添加的文件列表(“deviceready”,
onDeviceReady,假);
//黑莓<5.0的旧版本不支持
//PhoneGap的自定义事件,因此我们需要执行
//每隔500毫秒进行一次间隔检查,以查看
//PhoneGap已准备就绪。完成后,间隔将为
//可以开始清除和正常处理。
intervalID=window.setInterval(函数(){
如果(PhoneGap.available){
ondevicerady();
}
}, 500);
}
函数ondevicerady(){
窗口。clearInterval(intervalID);
//设置为真
isPhoneGapReady=true;
警报(“设备现在已准备就绪”);
}
//设置一个onload处理程序来调用init函数
window.onload=init;

是,在ChromeEyes的Ripple extension中,在chrome的Ripple extension中