Phonegap Geolocation错误:超时

use*_*557 8 iphone geolocation ios cordova

我有最新的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);}
Run Code Online (Sandbox Code Playgroud)

谢谢!

May*_*ari 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>
Run Code Online (Sandbox Code Playgroud)