-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpickup.html
92 lines (72 loc) · 2.41 KB
/
pickup.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
<script>
const next_event_lat = 39.2840112;
const next_event_lon = -76.6216646;
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge:Infinity
};
function myLogger(string) {
var node = document.createElement("LI");
var textnode = document.createTextNode(string);
node.appendChild(textnode);
document.getElementById("myList").appendChild(node);
}
function success(pos) {
var crd = pos.coords;
myLogger('Your current position is:');
myLogger(`Latitude : ${crd.latitude}`);
myLogger(`Longitude: ${crd.longitude}`);
myLogger(`More or less ${crd.accuracy} meters.`);
myLogger('Distance to Event');
myLogger('Oriole Park at Camden Yards: ' + getDistanceFromLatLonInKm(next_event_lat,next_event_lon,crd.latitude,crd.longitude).toFixed(1) + ' km');
}
function error(err) {
myLogger(`ERROR(${err.code}): ${err.message}`);
}
function getDistanceFromLatLonInKm(lat1,lon1,lat2,lon2) {
var R = 6371; // Radius of the earth in km
var dLat = deg2rad(lat2-lat1); // deg2rad below
var dLon = deg2rad(lon2-lon1);
var a =
Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
Math.sin(dLon/2) * Math.sin(dLon/2)
;
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c; // Distance in km
return d;
}
function deg2rad(deg) {
return deg * (Math.PI/180)
}
navigator.geolocation.getCurrentPosition(success, error, options);
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.watchPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
// x.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude;
var y = document.getElementById("distance");
y.innerHTML = 'Oriole Park at Camden Yards: ' + getDistanceFromLatLonInKm(next_event_lat,next_event_lon,position.coords.latitude,position.coords.longitude).toFixed(1) + ' km';
}
</script>
<style>
@media (min-width:1025px) { .container { width: 50% !important;} }
</style>
<center>
<div class="container">
<center>
<div class="row" style='text-align:left;'>
<ul id="myList">
</ul>
<button onclick="getLocation()">Check Location to Claim</button>
<h1 id="distance"></h1>
<p id="demo"></p>
</div>
</center>
</div>