이 아닌 문서의 최신 버전입니다!
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 (운영 체제 5.0와 더 높은)
- iOS
- Tizen
- Windows Phone 7과 8
- 윈도우 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>