forked from skjApp/HTML5-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeolocationAdvanced3.htm
52 lines (40 loc) · 1.19 KB
/
GeolocationAdvanced3.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE HTML>
<html>
<head>
<title>Example - Geolocation Advanced 3</title>
</head>
<body>
<input id = 'button1' type = 'button' value = 'Clear Location Watch'/>
<script type="text/javascript">
var watchID ;
function watchLocation()
{
if (navigator.geolocation)
{
watchID = navigator.geolocation.watchPosition(success, showError, {maximumAge:300000, timeout:30000});
}
else
{
document.writeln("Geolocation is not supported by this browser.");
}
}
function success(position)
{
document.writeln("Latitude: " + position.coords.latitude + " degrees <br/>Longitude: " + position.coords.longitude + " degrees <br/>Accuracy: " + position.coords.accuracy + " metres") ;
}
function showError(error)
{
alert("Error Code : " + error.code + "\nError Message : " + error.message) ;
}
document.writeln('Wait...') ;
watchLocation() ;
function clearWatchLocation()
{
navigator.geolocation.clearWatch(watchId);
}
// To clear watchLocation
var button1 = document.getElementById('button1') ;
button1.onclick = clearWatchLocation ;
</script>
</body>
</html>