git ssb

0+

Dominic / %oZNumvaRdlZDV/jsRcA…



Tree: 461be9d29ffa9ae1336651570c5ac4d45c8baa3a

Files: 461be9d29ffa9ae1336651570c5ac4d45c8baa3a / index.html

5180 bytesRaw
1<!DOCTYPE html>
2<html>
3<head>
4<title>---</title>
5<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
6<meta charset=utf-8></head>
7<style>
8
9h1 {
10 font-size: 5em;
11 margin-top: 10px;
12 margin-bottom: 10px;
13
14}
15
16h3 {
17 font-size: 2em;
18}
19
20</style>
21<body></body>
22<script>
23(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
24var GreatCircle = require('great-circle')
25
26var pre = document.createElement('pre')
27var speed = document.createElement('h1')
28var position = document.createElement('h3')
29document.body.appendChild(speed)
30document.body.appendChild(position)
31document.body.appendChild(pre)
32
33function flatten (p) {
34 var o = {}
35 for(var k in p)
36 if(p[k] && 'object' === typeof p[k])
37 o[k] = flatten(p[k])
38 else
39 o[k] = p[k]
40 return o
41}
42
43var DEGREE_SYMBOL = '\u00b0'
44
45
46function decimalTudeToMinutes (tude) {
47 return ~~tude.toString()+DEGREE_SYMBOL+Math.abs((tude - ~~(tude))*60).toPrecision(4)
48}
49
50var positions = []
51
52pre.textContent = 'waiting for position...'
53
54function round(r, n) {
55 var f = Math.pow(10, n)
56 return Math.round(r*f)/f
57}
58
59navigator.geolocation.watchPosition(function (e) {
60 positions.push(flatten(e))
61 //keep just one minute's worth of locations.
62
63 while(positions.length && positions[0].timestamp < Date.now() - 60e3) // one minute
64 positions.shift()
65
66 var lat = e.coords.latitude, long = e.coords.longitude
67 var movement = positions.map(function (_e) {
68 var _lat = _e.coords.latitude, _long = _e.coords.longitude
69 var time = e.timestamp - _e.timestamp
70 return {
71 distance: GreatCircle.distance(_lat, _long, lat, long, 'NM'),
72 heading: GreatCircle.bearing(_lat, _long, lat, long),
73 speed: GreatCircle.distance(_lat, _long, lat, long, 'NM') / (time / (1000*60*60)),
74 time: (e.timestamp - _e.timestamp)/1000
75 }
76 })
77
78 position.textContent = (
79 decimalTudeToMinutes(e.coords.latitude)
80 + ', ' +
81 decimalTudeToMinutes(e.coords.longitude)
82 )
83
84 E = e
85 var metersPerSecond = e.coords.speed || 0
86 var metersPerHour = metersPerSecond*3600
87 var metersPerNauticalMile = 1852.001
88 var knots = metersPerHour/metersPerNauticalMile
89 speed.textContent = round(knots, 2)
90 pre.textContent = JSON.stringify(movement, null, 2)
91}, function (err) {
92 pre.textContent = JSON.stringify({error:err.code, message: err.message}, null, 2)
93}, {
94 enableHighAccuracy: true,
95 timeout: 5000,
96 maximumAge: 0
97})
98
99
100},{"great-circle":2}],2:[function(require,module,exports){
101var GreatCircle = {
102
103 validateRadius: function(unit) {
104 var r = {'M': 6371009, 'KM': 6371.009, 'MI': 3958.761, 'NM': 3440.070, 'YD': 6967420, 'FT': 20902260};
105 if ( unit in r ) return r[unit];
106 else return unit;
107 },
108
109 distance: function(lat1, lon1, lat2, lon2, unit) {
110 if ( unit === undefined ) unit = 'KM';
111 var r = this.validateRadius(unit);
112 lat1 *= Math.PI / 180;
113 lon1 *= Math.PI / 180;
114 lat2 *= Math.PI / 180;
115 lon2 *= Math.PI / 180;
116 var lonDelta = lon2 - lon1;
117 var a = Math.pow(Math.cos(lat2) * Math.sin(lonDelta) , 2) + Math.pow(Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(lonDelta) , 2);
118 var b = Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(lonDelta);
119 var angle = Math.atan2(Math.sqrt(a) , b);
120
121 return angle * r;
122 },
123
124 bearing: function(lat1, lon1, lat2, lon2) {
125 lat1 *= Math.PI / 180;
126 lon1 *= Math.PI / 180;
127 lat2 *= Math.PI / 180;
128 lon2 *= Math.PI / 180;
129 var lonDelta = lon2 - lon1;
130 var y = Math.sin(lonDelta) * Math.cos(lat2);
131 var x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(lonDelta);
132 var brng = Math.atan2(y, x);
133 brng = brng * (180 / Math.PI);
134
135 if ( brng < 0 ) { brng += 360; }
136
137 return brng;
138 },
139
140 destination: function(lat1, lon1, brng, dt, unit) {
141 if ( unit === undefined ) unit = 'KM';
142 var r = this.validateRadius(unit);
143 lat1 *= Math.PI / 180;
144 lon1 *= Math.PI / 180;
145 var lat3 = Math.asin(Math.sin(lat1) * Math.cos(dt / r) + Math.cos(lat1) * Math.sin(dt / r) * Math.cos( brng * Math.PI / 180 ));
146 var lon3 = lon1 + Math.atan2(Math.sin( brng * Math.PI / 180 ) * Math.sin(dt / r) * Math.cos(lat1) , Math.cos(dt / r) - Math.sin(lat1) * Math.sin(lat3));
147
148 return {
149 'LAT': lat3 * 180 / Math.PI,
150 'LON': lon3 * 180 / Math.PI
151 };
152 }
153
154}
155
156if (typeof module != 'undefined' && module.exports) {
157 module.exports = GreatCircle;
158} else {
159 window['GreatCircle'] = GreatCircle;
160}
161
162},{}]},{},[1]);
163</script>
164</html>
165

Built with git-ssb-web