我正在请求我的用户使用以下功能从浏览器获取他们的位置:
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(set_map_location,geoloc_error,{
enableHighAccuracy:false,
maximumAge:85000,
timeout:15000
});
}
如果出现问题或进程超时,我的geoloc_err
函数会被调用:
function geoloc_error(err) {
if (err.code == 1) {
alert("You denied the browser access to your location."
+ "\nYou can find your position manually by dragging the map and zooming in/out.");
} else if (err.code == 2) {
alert("The geolocation network is not available or your position could not be found."
+ "\nYou can find your position manually by dragging the map and zooming in/out.");
} else {
alert("The browser took too long to find your location. Trying again can sometimes yield different results.\n"
+ "You can find your position manually by dragging the map and zooming in/out.");
}
}
现在,有时会发生错误,例如err.code==2 the network was unavailable
,并且会弹出警告并警告我。问题是,几秒钟后,另一个警告框警告我该过程也已超时。
我的问题是,如何停止发生第二次错误警告?我无法退出该函数,因为正在从第一个函数调用错误。