Geolocation: clearWatch() メソッド
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。
Geolocation.clearWatch() メソッドは、以前 Geolocation.watchPosition() によって登録された位置情報/エラーの監視ハンドラーを解除するために使用します。
構文
js
clearWatch(id) 引数
id-
解除したいハンドラーの登録時に
Geolocation.watchPosition()メソッドから返された ID 番号です。
返値
なし (undefined)。
例
js
let id; let target; let options; function success(pos) { const crd = pos.coords; if (target.latitude === crd.latitude && target.longitude === crd.longitude) { console.log("Congratulations, you've reached the target!"); navigator.geolocation.clearWatch(id); } } function error(err) { console.error(`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> # clearwatch-method> |