Phonegap Geolocation错误:超时

时间:2011-11-21 17:13:00

标签: iphone ios cordova geolocation

我已经获得了最新的phonegap 1.2,并将文档中的测试代码放入我的应用程序中。当我在模拟器(xcode 4.2模拟器5.0)和运行5的iPad上运行我的应用程序时,我收到错误“Geolocation Error:timeout”。

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

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

谢谢!

3 个答案:

答案 0 :(得分:0)

我认为你错过了脚本文件导入问题。您需要导入phonegap-1.2.0.js而不是phonegap.js

在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>

答案 1 :(得分:0)

iMayur的答案显示,非原生地理位置API正在运行。如果您第一次在iPhone上调用此脚本,则会向浏览器HTML5 api询问“地理位置访问问题”。

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

[编辑]

已开启新问题:Issuetracker #304

答案 2 :(得分:0)

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

相关问题