[英]navigator.geolocation.getcurrentposition throws Timeout error
[英]navigator.geolocation.getCurrentPosition always get a error code 3: timeout expired
我使用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");
}
如果有人知道為什么會引發error3
,請提出建議。 非常感謝
我確實設定了
enableHighAccuracy: false
也是,但是害怕“錯誤代碼3”不斷出現......兩者都沒有
browser / settings / privacy and security / position / delete position access data
確實有幫助...只有電源循環(但我認為瀏覽器殺死會做同樣的事情)Android(4.1.2)確實迫使瀏覽器重復“分享位置?”這個問題。 對用戶,拋出錯誤代碼3 ...
我想在某些情況下(我不能重復,抱歉)瀏覽器存儲該網站的無效位置 - 或者 - 記住該網站的共享拒絕...
很抱歉遲到回答(也許是以不完整的方式)...如果有人有更好的證據請分享... :-)
這困擾了我很長一段時間。 基本上我唯一能讓它返回數據的方法就是專門傳遞
enableHighAccuracy: false
如果我啟用它總是超時。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.