From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/api/geolocation/watchposition/index.html | 99 ++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 files/ja/web/api/geolocation/watchposition/index.html (limited to 'files/ja/web/api/geolocation/watchposition') diff --git a/files/ja/web/api/geolocation/watchposition/index.html b/files/ja/web/api/geolocation/watchposition/index.html new file mode 100644 index 0000000000..908f8b061d --- /dev/null +++ b/files/ja/web/api/geolocation/watchposition/index.html @@ -0,0 +1,99 @@ +--- +title: Geolocation.watchPosition() +slug: Web/API/Geolocation/watchPosition +tags: + - API + - Geolocation + - Geolocation API + - Method + - Reference + - Secure context +translation_of: Web/API/Geolocation/watchPosition +--- +

{{securecontext_header}}{{ APIref("Geolocation API") }}

+ +

{{domxref("Geolocation")}} の watchPosition() メソッドは、端末の位置が変化するたびに自動的に呼び出されるハンドラー関数を登録するために用いられます。また必要に応じてエラー処理コールバック関数を指定することができます。

+ +

構文

+ +
navigator.geolocation.watchPosition(success[, error[, options]])
+ +

引数

+ +
+
success
+
コールバック関数で、 {{domxref("GeolocationPosition")}} オブジェクトを入力引数として受け取るものです。
+
error {{optional_inline}}
+
任意のコールバック関数で、 {{domxref("GeolocationPositionError")}} オブジェクトを入力引数として受け取るものです。
+
options {{optional_inline}}
+
任意の {{domxref("PositionOptions")}} オブジェクトで、位置を監視する構成オプションを提供します。
+
+ +

返値

+ +

登録されたハンドラーを識別する ID を返します。この ID を {{domxref("Geolocation.clearWatch()")}} メソッドに渡してハンドラーの登録を解除することができます。

+ +

+ +
var id, target, options;
+
+function success(pos) {
+  var crd = pos.coords;
+
+  if (target.latitude === crd.latitude && target.longitude === crd.longitude) {
+    console.log('Congratulations, you reached 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);
+
+ +

仕様書

+ + + + + + + + + + + + + + + + +
仕様書状態備考
{{SpecName('Geolocation', '#dom-geolocation-watchposition', 'watchPosition()')}}{{Spec2('Geolocation')}}初回定義
+ +

ブラウザーの互換性

+ + + +

{{Compat("api.Geolocation.watchPosition")}}

+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf