2012-07-04 6 views
0

나는 phonegap을 가진 초보자입니다. 나는 장치의 위치를 ​​얻는 앱을 만들고있다. 나는 삼성 갤럭시 탭과 HTC로 테스트를했으나 아무 것도하지 않는다. 나는 장치의 속도를 얻으려고 노력한다. 화면에서 div. 이건 내 코드입니다 :phonegap 앱이 작동하지 않습니다.

위치 정보 :

// 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'); 
    } 

내가 리플, 크롬의 확장에서 테스트 한, 그리고 ...이 속도의 값을 변경, 잘 작동하고 잘 작동하지만, 장치로, 나는 왜 모르겠다. 왜 될 수 있습니까? 안부, 다니엘은

나는 어쩌면 {enableHighAccuracy을 : TRUE} 추가 할 필요 읽었습니다

VAR 옵션에 ... 그러나 나는이 이해가 안 ...

+1

에뮬레이터에서 작동합니까? – Aamirkhan

+0

예, 크롬의 리플 확장에서 – Daniel

답변

3

음 다니엘, 먼저 내가하는 것이 좋습니다 이 일반적인 PhoneGap 앱을 사용하여 기기를 사용할 준비가되었는지 테스트합니다. 그렇다면 디스플레이 경고 메시지가 표시되면서 경고 메시지가 표시되고, 정상적으로 작동하면 코드에 문제가있어 다시 돌아갑니다. 확인해 봐. 여기에 있습니다 :

// 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; 
관련 문제