gpt4 book ai didi

android - phonegap HTML5 地理定位

转载 作者:行者123 更新时间:2023-11-29 13:57:48 25 4
gpt4 key购买 nike

我试图用 HTML5 获取我的位置坐标,但它每次都给我错误。

这是我写给phone gap android项目的代码

我在 phone gap geolocation 的文档中使用了相同的代码。并添加对函数 device-ready () 的调用以了解此代码是否正在运行

它给了我

error 2 : messege 2 :    the last location provider was disabled 

这是我用来在 Android 设备上获取位置的代码!

<!DOCTYPE html>
<html>
<head>
<title>Device Properties Example</title>

<script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"></script>
<script type="text/javascript" charset="utf-8">

// Wait for PhoneGap to load
//
document.addEventListener("deviceready", onDeviceReady, false);

var watchID = null;

// PhoneGap is ready
//
function onDeviceReady() {
// Update every 3 seconds
var options = { frequency: 3000 };
watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
}

// onSuccess Geolocation
//
function onSuccess(position) {
var element = document.getElementById('geolocation');
element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +
'Longitude: ' + position.coords.longitude + '<br />' +
'<hr />' + element.innerHTML;

//alert("the lang is : "+position.coords.latitude);
document.write("the lang is : "+position.coords.latitude);

}

// clear the watch that was started earlier
//
function clearWatch() {
if (watchID != null) {
navigator.geolocation.clearWatch(watchID);
watchID = null;
}
}

// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}

</script>
</head>
<body>


<p id="geolocation">Watching geolocation...</p><br>
<button onclick="onDeviceReady();">onDeviceReady()</button> <br>
<button onclick="clearWatch();">Clear Watch</button> <br>

<a href="index2.html"> index 2 </a>
</body>
</html>

我从这里得到这个教程 http://docs.phonegap.com/en/1.7.0/cordova_geolocation_geolocation.md.html#Geolocation !

希望建议我该怎么做!!

最佳答案

尝试将选项 enableHighAccuracy 设置为 true

关于android - phonegap HTML5 地理定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11088072/

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