/
index.html
94 lines (81 loc) · 2.11 KB
/
index.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
85
86
87
88
89
90
91
92
93
94
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>SCWD GEOLOCO</title>
<style>
*{
margin:0;
padding:0;
}
#container{
background-color:#6899D3;
width:800px;
margin:40px auto 0;
padding:20px;
color:#fff;
-webkit-border-radius:5px;
-moz-border-radius:5px;
-webkit-box-shadow:#000 0 0 20px;
-moz-box-shadow:#000 0 0 20px;
text-shadow:#000 1px 1px 1px;
}
</style>
</head>
<body>
<div id="container">
<p id="">Latitude:</p>
<p id="lat"></p>
<p id="">Longitude:</p>
<p id="lon"></p>
<p id="pairs"></p>
</div><!--end of container div-->
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function() {
getGeo()
})
</script>
<script>
// create getGeo() function
function getGeo() {
// get the users lat and lon with html5 geolocation api
navigator.geolocation.watchPosition(function(position, handle_error, enableHighAccuracy) {
// assign lon and lat to vars
var latitude = position.coords.latitude
var longitude = position.coords.longitude
// print to screen
$("#lat").html(latitude)
$("#lon").html(longitude)
//call the doSetItem() function
doSetItem()
}) // end of watchPosition
} // end of getGeo()
function doSetItem() {
// assign lat and lon to var
var storageLat = $("#lat").text()
var storageLon = $("#lon").text()
// create date object
var dateStamp = new Date()
// create JSON for storage
var storageObject = {"Latitude:": storageLat, "Longitude:": storageLon}
// stringify object
var stringyObject = JSON.stringify(storageObject)
// write to local storage using HTML5 localStorage API
localStorage.setItem(dateStamp, stringyObject)
// call the doGetItem() function
doGetItem()
} // end of doSetItem()
function doGetItem() {
var key = "";
var pairs = "<tr><th>Date</th><th>Location</th></tr>\n";
var i=0;
for (i=0; i<=localStorage.length-1; i++) {
key = localStorage.key(i);
pairs += "<tr><td>"+key+"</td>\n<td>"+localStorage.getItem(key)+"</td></tr>\n";
} // end of for()
$('#pairs').html(pairs)
} // end of doGetItem()
</script>
</body>
</html>