Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Geolocation.clearWatch()

Geolocation.clearWatch() 這個函式是用來取消   Geolocation.watchPosition() 註冊的函式。

語法

navigator.geolocation.clearWatch(id);

參數

編號(id)
這個編號(ID) 是由 Geolocation.watchPosition() 這個函式所回傳,當你不再需要收到位置更新時,你可以用此編號,取消 Geolocation.watchPosition() 的註冊。

範例

var id, target, option;

function success(pos) {
  var crd = pos.coords;

  if (target.latitude === crd.latitude && target.longitude === crd.longitude) {
    console.log('Congratulation, you reach the target');
    navigator.geolocation.clearWatch(id);
  }
};

function error(err) {
  console.warn('ERROR(' + err.code + '): ' + err.message);
};

target = {
  latitude : 0,
  longitude: 0,
}

options = {
  enableHighAccuracy: false,
  timeout: 5000,
  maximumAge: 0
};

id = navigator.geolocation.watchPosition(success, error, options);

規格

Specification Status Comment
Geolocation API Recommendation Initial specification.

瀏覽器的相容性

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 5 3.5 (1.9.1) 9 10.60
Removed in 15.0
Reintroduced in 16.0
5
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? ? 4.0 (4) ? 10.60 ?

請參考

文件標籤與貢獻者

 此頁面的貢獻者: yachiehwu
 最近更新: yachiehwu,