我嘗試了多種策略,直到找到一個結果,如果不是我做一個拉的每一分鐘。或多或少像這樣:
function calculatePosition(timeout, maxAge, accuracy, step){
navigator.geolocation.getCurrentPosition(
function(position){
console.log("success");
},
function(error){
nextStep(step + 1);
},
{enableHighAccuracy: accuracy,
timeout: timeout,
maximumAge: maxAge}
);
}
function nextStep(step){
switch(step){
case 0:
calculatePosition(1000, 604800000, false, step);
break;
case 1:
calculatePosition(1000, 604800000, true, step);
break;
case 2:
calculatePosition(5000, 4000, false, step);
break;
case 3:
calculatePosition(5000, 4000, true, step);
break;
case 5:
calculatePosition(50000, 60000, true, step);
break;
case 6:
calculatePosition(50000, 60000, false, step - 2);
break;
}
}
nextStep(0);
您是在真實設備還是在eclipse仿真器中測試它? – TlmaK0 2014-10-18 11:06:14
我都在測試 – 2014-10-18 12:34:02