We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

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.

瀏覽器的相容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

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,