【问题标题】:Phonegap Geolocation Error: timeoutPhonegap 地理位置错误:超时
【发布时间】:2012-01-03 04:19:41
【问题描述】:

我有最新的 phonegap 1.2 并将文档中的测试代码放入我的应用程序中。当我在模拟器(xcode 4.2 模拟器 5.0)和运行 5 的 iPad 上运行我的应用程序时,我收到错误“地理位置错误:超时”。

有其他人经历过吗?这是我的代码:

document.addEventListener("deviceready", onDeviceReady, false);
        // PhoneGap is ready
        function onDeviceReady() {
        var myOptions = { enableHighAccuracy: true };
        navigator.geolocation.getCurrentPosition(onSuccess, onError,myOptions);}

谢谢!

【问题讨论】:

    标签: iphone ios cordova geolocation


    【解决方案1】:

    不知道他们是否为你修好了。 现在假设您的代码是正确的: navigator.geolocation.getCurrentPosition(onSuccess, onError,{'enableHighAccuracy':true,'timeout':10000}); 添加超时部分,应该不会再报超时错误了。

    【讨论】:

      【解决方案2】:

      iMayur 的回答显示,非本地地理定位 API 正在工作。如果您第一次在 iphone 上调用此脚本,浏览器 HTML5 api 会询问您“地理位置访问问题”。

      我认为这是 phonegap 的一个更大问题:Issuetracker #197

      [编辑]

      有一个新问题打开了:Issuetracker #304

      【讨论】:

        【解决方案3】:

        我认为您缺少脚本文件导入问题。您需要导入phonegap-1.2.0.js 而不是phonegap.js

        以下 sn-p 在 iOS 5 模拟器和设备上的工作。

        <!DOCTYPE html>
        <html>
            <head>
                <title>Device Properties Example</title>
                <script type="text/javascript" charset="utf-8" src="phonegap-1.2.0.js"></script>
                <script type="text/javascript" charset="utf-8">
                    // Wait for PhoneGap to load
                    document.addEventListener("deviceready", onDeviceReady, false);
                    // PhoneGap is ready
                    function onDeviceReady() {
                         var myOptions = { enableHighAccuracy: true };
                        navigator.geolocation.getCurrentPosition(onSuccess, onError,myOptions);
                    }
                    // onSuccess Geolocation
                    function onSuccess(position) {
                        var element = document.getElementById('geolocation');
                        element.innerHTML = 'Latitude: '           + position.coords.latitude              + '
        ' + 'Longitude: ' + position.coords.longitude + '
        ' + 'Altitude: ' + position.coords.altitude + '
        ' + 'Accuracy: ' + position.coords.accuracy + '
        ' + 'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '
        ' + 'Heading: ' + position.coords.heading + '
        ' + 'Speed: ' + position.coords.speed + '
        ' + 'Timestamp: ' + new Date(position.timestamp) + '
        '; } // 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>

        【讨论】:

        • 如果您使用的是 PhoneGap Build,导入 phonegap.js 实际上没问题:Build 嵌入了 phonegap.js 和 phonegap-x.y.z.js 的最新稳定版本。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-23
        • 2016-03-26
        • 2012-10-03
        • 2023-03-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多