gpt4 book ai didi

iphone - Phonegap 地理位置错误 : timeout

转载 作者:可可西里 更新时间:2023-11-01 03:21:36 24 4
gpt4 key购买 nike

我有最新的 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);}

谢谢!

最佳答案

我认为您缺少脚本文件导入问题。您需要导入 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 + '<br/>' +
'Longitude: ' + position.coords.longitude + '<br/>' +
'Altitude: ' + position.coords.altitude + '<br/>' +
'Accuracy: ' + position.coords.accuracy + '<br/>' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '<br/>' +
'Heading: ' + position.coords.heading + '<br/>' +
'Speed: ' + position.coords.speed + '<br/>' +
'Timestamp: ' + new Date(position.timestamp) + '<br/>';
}
// 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>

关于iphone - Phonegap 地理位置错误 : timeout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8215681/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com