我已經在我的項目中實現了HTML地理位置功能,但是我注意到它並不總是可靠的。HTML5地理位置超時
如何在x秒後添加回退到超時並顯示錯誤?
這裏是我的代碼:
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
else{x.innerHTML = "Geolocation is not supported by this browser, please manually enter your postcode above";}
);
}
function showPosition(position)
{
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
可能的重複http://stackoverflow.com/questions/3397585/navigator-geolocation-getcurrentposition-sometimes-works-sometimes-doesnt – mccainz