MDN’s new design is in Beta! A sneak peek: https://blog.mozilla.org/opendesign/mdns-new-design-beta/

Geolocation.clearWatch()

Geolocation.clearWatch()这个方法主要用于使用 Geolocation.watchPosition() 注册的 位置/错误 监听器。

语法

navigator.geolocation.clearWatch(id);

参数

id
希望移除的监听器所对应的 Geolocation.watchPosition() 返回的 ID 数字。

示例

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);

规范

规范 状态 说明
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 ?

 

相关链接

文档标签和贡献者

 此页面的贡献者: Cattla
 最后编辑者: Cattla,