-
Notifications
You must be signed in to change notification settings - Fork 0
/
gMapsTest.html
130 lines (110 loc) · 3.31 KB
/
gMapsTest.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<style>
.slidecontainer {
width: 100%;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 25px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider:hover {
opacity: 1;
}
</style>
</head>
<body>
<p id="text"></p>
<div class="slidecontainer">
<p>Default range slider:</p>
<input id="myRange" type="range" min="0" max="20" value="1">
<p>Value: <span id="demo"></span></p>
<script>
var slider = document.getElementById("myRange");
var output = document.getElementById("demo");
output.innerHTML = slider.value;
var disti = 1;
slider.oninput = function() {
disti = this.value;
output.innerHTML = disti;
}
</script>
<script type="text/javascript">
var x = document.getElementById("text");
var posLng;
var posLat;
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
navigator.geolocation.getCurrentPosition(checkLocation);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
//console.log(posLat);
console.log("yes is running show");
}
function checkLocation(position){
posLat = position.coords.latitude;
posLng = position.coords.longitude;
// 29.678196230958015, -82.29569554602904
let galleries = '{"galleries":[' +
'{"name":"Santa Fe College Gallery","latitude":"29.680095271019443","longitude":"-82.43478467358335" },' +
'{"name":"Curia","latitude":"29.67198651033575","longitude":"-82.33024074659807" },' +
'{"name":"Moisturizer","latitude":"29.678196230958015","longitude":"-82.29569554602904" }]}';
const gParse = JSON.parse(galleries);
console.log(gParse);
console.log(posLat);
var key, length = 0;
for(key in gParse.galleries) {
if(gParse.galleries.hasOwnProperty(key)) {
length++;
}
}
// var length = Object.keys(galleries).length;
console.log(length + 'number of galleries');
for (var i = 0; i < length; i++) {
if (calcCrow(gParse.galleries[i].latitude,
gParse.galleries[i].longitude,
posLat,posLng)<= disti){
//do something
x.innerHTML += gParse.galleries[i].name+"....this gallery is within_" + disti + "_miles of you"+"<br>";
console.log(gParse.galleries[i].name+"_this gallery is within half a mile of you");
}
}
}
function calcCrow(coords1lat,coords1lng,coords2lat,coords2lng)
{
// var R = 6.371; // km
var R = 69;
var dLat = toRad(coords2lat-coords1lat);
var dLon = toRad(coords2lng-coords1lng);
var lat1 = toRad(coords1lat);
var lat2 = toRad(coords2lat);
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = c;
var deg = (d * 180/Math.PI) * 69;
console.log(deg+ 'distance');
return deg;
}
// Converts numeric degrees to radians
function toRad(Value)
{
return Value * Math.PI / 180;
}
</script>
<button onclick="getLocation()">Try It</button>
</body>
</html>