これがないドキュメントの最新バージョンです!
Click here for the latest released version.
geolocation.clearWatch
によって参照される、デバイスの場所への変更を見て停止、 watchID
パラメーター。
navigator.geolocation.clearWatch(watchID);
パラメーター
- watchID: の id、
watchPosition
をクリアする間隔。(文字列)
説明
geolocation.clearWatch
をオフにして、デバイスの場所の変更を見て停止します、 [geolocation.watchPosition](geolocation.watchPosition.html)
によって参照されます。watchID
.
サポートされているプラットフォーム
- アンドロイド
- ブラックベリー WebWorks (OS 5.0 およびより高い)
- iOS
- Tizen
- Windows Phone 7 と 8
- Windows 8
簡単な例
//オプション: 位置の変化を監視し、頻繁に使用//正確な位置取得法利用可能。
//
var watchID = navigator.geolocation.watchPosition(onSuccess, onError, { enableHighAccuracy: true });
// ...later on...
navigator.geolocation.clearWatch(watchID);
完全な例
<!DOCTYPE html>
<html>
<head>
<title>Device Properties Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
document.addEventListener("deviceready", onDeviceReady, false);
var watchID = null;
// device APIs are available
//
function onDeviceReady() {
// Get the most accurate position updates available on the
// device.
var options = { enableHighAccuracy: true };
watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
}
// onSuccess Geolocation
//
function onSuccess(position) {
var element = document.getElementById('geolocation');
element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +
'Longitude: ' + position.coords.longitude + '<br />' +
'<hr />' + element.innerHTML;
}
// clear the watch that was started earlier
//
function clearWatch() {
if (watchID != null) {
navigator.geolocation.clearWatch(watchID);
watchID = null;
}
}
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
</script>
</head>
<body>
<p id="geolocation">Watching geolocation...</p>
<button onclick="clearWatch();">Clear Watch</button>
</body>
</html>