【问题标题】:PhoneGap-2.9.0 navigator.geolocation.getCurrentPosition(onSuccess, onError); not workingPhoneGap-2.9.0 navigator.geolocation.getCurrentPosition(onSuccess, onError);不工作
【发布时间】:2014-08-05 11:08:47
【问题描述】:
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">

    document.addEventListener("deviceready", onDeviceReady, false);

    function onDeviceReady() { alert('onDeviceReady Function works');
        var option = {frequency:500,maximumAge: 0, timeout: 1000, enableHighAccuracy:true};
        navigator.geolocation.getCurrentPosition(onSuccess, onError, option );
    }

    function onSuccess(position) { alert("It Works!!!");
        var element = document.getElementById('geolocation');
        element.innerHTML = 'Latitude: '  + position.coords.latitude  + '<br />' +
                            'Longitude: ' + position.coords.longitude;
    }

    function onError(error) {
         //alert(error);
        alert('code: '    + error.code    + '\n' + 'message: ' + error.message + '\n');
    }

 </script>


<p id="geolocation">Finding geolocation...</p>

以上代码deviceready() 函数工作正常,但alert("It Works!!!"); 不工作。请告诉我为什么它在我的设备模拟器中不起作用?

我收到错误消息。

截图:

【问题讨论】:

  • LogCat 中是否有任何错误?
  • 是的,请再次检查更新的问题
  • @Shankar 请帮帮我..
  • 尝试增加 timeout 并增加 maximumAge { maximumAge: 3000, timeout: 5000, enableHighAccuracy: true };

标签: android cordova


【解决方案1】:

timeout 增加到 '5000' 或 '10000' 并增加 maximumAge

 { maximumAge: 3000, timeout: 5000, enableHighAccuracy: true };

检查PhoneGap Error documentation

【讨论】:

  • 我增加了超时 10000。我在 10 秒后收到相同的错误消息警报
  • 你是在设备还是模拟器中测试?
  • 我正在模拟器中测试
猜你喜欢
  • 2012-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-25
  • 1970-01-01
  • 1970-01-01
  • 2013-09-10
  • 2014-05-22
相关资源
最近更新 更多