use*_*576 11 android geolocation
我使用cordova-2.0.0和android模拟器google api level16.
每当我跑步,navigator.geolocation.getCurrentPosition我总是得到error3.我的代码简介如下:
// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
function onDeviceReady() {
console.log("Entering index.html.onDeviceReady");
var networkState = navigator.network.connection.type;
getPosition(networkState);
}
function getPosition(networkState) {
console.log("Entering getPosition function");
console.log("networkState is: " + networkState);
if (networkState !== null) {
navigator.geolocation.getCurrentPosition(onSuccess, onError, {
maximumAge : Infinity,
timeout : 5000,
enableHighAccuracy : true
});
} else {
alert('Please check your network connection and try again.');
}
console.log("Leaving getPosition function");
}
// function for lat & lng
function onSuccess(position) {
console.log("Entering onSuccess(position) function");
console.log("Latitude is: " + position.coords.latitude);
console.log("longitude is: " + position.coords.longitude);
lat = position.coords.latitude;
lng = position.coords.longitude;
console.log("Leaving onSuccess(position) function");
}
// function for lat & lng
function onError(error) {
console.log("Entering onError(error) function");
alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n');
console.log("Leaving onError(error) function");
}
Run Code Online (Sandbox Code Playgroud)
如果有人知道为什么error3被提出,请提出建议.非常感谢
我确实设定了
enableHighAccuracy: false
Run Code Online (Sandbox Code Playgroud)
也是如此,但是害怕"错误代码3"不断出现......两者都没有
browser / settings / privacy and security / position / delete position access data
Run Code Online (Sandbox Code Playgroud)
确实有帮助...只有电源循环(但我认为浏览器杀死会做同样的事情)Android(4.1.2)确实迫使浏览器重复"分享位置?"这个问题.对用户,抛出错误代码3 ...
我想在某些情况下(我不能重复,抱歉)浏览器存储该网站的无效位置 - 或者 - 记住该网站的共享拒绝...
很抱歉迟到回答(也许是以不完整的方式)...如果有人有更好的证据请分享... :-)
这让我困惑了好一阵子。基本上,我可以让它返回数据的唯一方法是专门传递
enableHighAccuracy: false
Run Code Online (Sandbox Code Playgroud)
如果我启用它,它总是超时。
| 归档时间: |
|
| 查看次数: |
13771 次 |
| 最近记录: |