phonegap geolocation always fail on timeout

前端 未结 11 712
遥遥无期
遥遥无期 2020-12-06 01:06

I\'m using sencha-touch 2.0 and phonegap 2.0.0 in my app to retrieve user\'s location. When runing on my locahost, everything works just fine. However, when loading the .apk

11条回答
  •  离开以前
    2020-12-06 01:47

    Try This Solution:

    window.setInterval(checkPosition, 5000);
    
    function checkPosition() {
     function onSuccess(position) {
        document.getElementById('result1').innerHTML = position.coords.latitude;
        document.getElementById('result2').innerHTML = position.coords.longitude;
     }
    
     // onError Callback receives a PositionError object
     //
     function onError(error) {
        alert('code: '    + error.code    + '\n' +
            'message: ' + error.message + '\n');
     }
     navigator.geolocation.getCurrentPosition(onSuccess, onError);
    }
    

提交回复
热议问题