Geolocation.clearWatch()
安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。
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);
仕様書
Specification |
---|
Geolocation API # clearwatch-method |
ブラウザーの互換性
BCD tables only load in the browser