-
Notifications
You must be signed in to change notification settings - Fork 0
/
geolocation.html
84 lines (76 loc) · 2.23 KB
/
geolocation.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html>
<head>
<title>Get your Geolocation</title>
</head>
<style>
div.hey4{
position:fixed;
top: 50%;
left: 50%;
transform: translate(-50%,-90%);
width: 40%;
height: 20%;
background-color: #808080;
box-shadow: 0px 0px 100px 40px #808080;
}
h1.set{
position: fixed;
bottom: 0;
top: 70%;
left: 35%;
}
</style>
<body bgcolor = "black">
<div class = "hey4" style="background-color: black; color:white; padding:5%;">
<div id="demo2" class = "hey11" onclick="Geolocation()" style="background-color: white; color:black; padding:5%;">
<center><h1>Get my Geolocation</h1></center>
</div>
</div>
<script>
//localStorage.clear();
function Geolocation()
{
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(Position,showError);
}
else {
document.getElementById("here").innerHTML = "Error";
}
}
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
document.getElementById("here").innerHTML = "ERROR: Request for Geolocation Denied"
break;
}
}
function Position(position) {
document.getElementById("here").innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude;
// if(typeof(Storage) !== "undefined") {
if (localStorage.click) {
localStorage.click = localStorage.click + "<br>Latitude :" + position.coords.latitude + "<br>Altitude :" + position.coords.longitude + "<br>";
} else {
localStorage.click = "";
localStorage.click = localStorage.click + "<br>Latitude :" + position.coords.latitude + "<br>Altitude :" + position.coords.longitude + "<br>";
}
document.getElementById("result").innerHTML = localStorage.click;
//} else {
// document.getElementById("result").innerHTML = "Sorry, your browser does not support web storage...";
// }
}
function clears()
{
localStorage.click = "";
history.go(0);
}
</script>
<h1 class = "set" style="color:white" id="here">
Latitude:<br>
Longitude:<br><br>
(Click on white area)
</h1>
<p><button onclick="clears()" type="button">Clear History</button></p>
<div id="result" style="color:white">Your location History :</div>
</body>
</html>