<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
meta
charset
=
"UTF-8"
>
<
meta
http-equiv
=
"X-UA-Compatible"
content
=
"IE=edge"
>
<
meta
name
=
"viewport"
content
=
"width=device-width, initial-scale=1.0"
>
<
title
>HTML Geolocation clearWatch() Method</
title
>
</
head
>
<
body
>
<
h2
>Welcome To GFG</
h2
>
<
button
onclick
=
"getPosition()"
>
Watch Position
</
button
>
<
p
id
=
"demo"
></
p
>
<
button
onclick
=
"clearPosition()"
>
Clear Position
</
button
>
<
script
>
var clearId;
var demoPara = document.getElementById("demo");
var user_loc = navigator.geolocation;
function getPosition() {
if (user_loc) {
var option = { timeout: 50000 }
clearId = user_loc.watchPosition(
currentLoc, resolveError, option);
}
else {
"Your browser doesn't support Geolocation API.";
}
}
function currentLoc(loc) {
var lat = loc.coords.latitude;
var long = loc.coords.longitude;
demoPara.innerHTML = "Latitude: "
+ lat + "<
br
>Longitude: " + long;
}
function resolveError(err) {
demoPara.innerHTML = "ERROR"
+ err.code + ": " + err.message;
}
function clearPosition() {
demoPara.innerHTML = user_loc.clearWatch(clearId);
}
</
script
>
</
body
>
</
html
>