WatchClear 方法 html5,clearWatch()
clearWatch()
描述 (Description)
clearWatch方法取消正在進行的watchPosition調用。 取消后,watchPosition調用將停止檢索有關設備當前地理位置的更新。
語法 (Syntax)
以下是此方法的語法 -clearWatch(watchId);
參數(shù) (Parameters)
這是參數(shù)的細節(jié) -watchId - 指定要取消的watchPosition調用的唯一ID。 該值由watchPosition調用返回。
返回值
clearWatch方法不返回值。
例子 (Example)
var watchID;
var geoLoc;
function showLocation(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
alert("Latitude : " + latitude + " Longitude: " + longitude);
}
function errorHandler(err) {
if(err.code == 1) {
alert("Error: Access is denied!");
} else if( err.code == 2) {
alert("Error: Position is unavailable!");
}
}
function getLocationUpdate(){
if(navigator.geolocation){
// timeout at 60000 milliseconds (60 seconds)
var options = {timeout:60000};
geoLoc = navigator.geolocation;
watchID = geoLoc.watchPosition(showLocation, errorHandler, options);
} else {
alert("Sorry, browser does not support geolocation!");
}
}
function stopWatch() {
geoLoc.clearWatch(watchID);
}
這將產(chǎn)生以下結果 -
新頁面打開
總結
以上是生活随笔為你收集整理的WatchClear 方法 html5,clearWatch()的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 加州大学戴维斯分校 计算机科学,加州大学
- 下一篇: win8 网络 连接计算机名称,win8