-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtracking.html
42 lines (37 loc) · 1.17 KB
/
tracking.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML GeoLocation Test</title>
<script type="text/javascript">
var watchID=0;
function startLocationTracking(){
if (navigator.geolocation) {
alert("Your Browser supports GeoLocation");
watchID = navigator.geolocation.watchPosition(showCurrentLocation,errorHandler,{enableHighAccuracy: true});
} else {
alert("Your Browser does not support GeoLocation.");
}
}
function showCurrentLocation(position){
document.getElementById("mylocation").innerHTML = "Tracking your position --> Current Latitude : " + position.coords.latitude + " , Longitude : " + position.coords.longitude;
}
function errorHandler(error){
alert("Error while retrieving current position. Error code: " + error.code + ",Message: " + error.message);
}
function stopLocationTracking(){
if (watchID > 0) {
navigator.geolocation.clearWatch(watchID);
alert("Stopped Tracking Location");
}
}
</script>
</head>
<body>
<div id="main">
<div id="mylocation"></div>
<input type="button" value="Start Tracking Me" onclick="startLocationTracking()"/>
<input type="button" value="Stop Tracking Me" onclick="stopLocationTracking()"/>
</div>
</body>
</html>