git ssb

0+

Dominic / %oZNumvaRdlZDV/jsRcA…



Tree: cfc9bab4fc428e2e8861ef1b092b3170e95c8d4a

Files: cfc9bab4fc428e2e8861ef1b092b3170e95c8d4a / index.html

3959 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<body></body>
8<script>
9(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){
10var GreatCircle = require('great-circle')
11
12var pre = document.createElement('pre')
13document.body.appendChild(pre)
14
15function flatten (p) {
16 var o = {}
17 for(var k in p)
18 if(p[k] && 'object' === typeof p[k])
19 o[k] = flatten(p[k])
20 else
21 o[k] = p[k]
22 return o
23}
24
25var positions = []
26
27pre.textContent = 'waiting for position...'
28
29navigator.geolocation.watchPosition(function (e) {
30 console.log(e.coords, e.timestamp)
31 positions.push(flatten(e))
32 //keep just one minute's worth of locations.
33 if(e.timestamp < Date.now() - 60e3) // one minute
34 positions.shift()
35
36 var movement = positions.map(function (_e) {
37 _e = _e.coords
38 return {
39 distance: GreatCircle.distance(_e.latitude, _e.longitude, e.latitude, e.longitude, 'NM'),
40 heading: GreatCircle.bearing(_e.latitude, _e.longitude, e.latitude, e.longitude)
41 }
42 })
43
44 pre.textContent = JSON.stringify({current: flatten(e), movement: movement}, null, 2)
45})
46
47
48},{"great-circle":2}],2:[function(require,module,exports){
49var GreatCircle = {
50
51 validateRadius: function(unit) {
52 var r = {'M': 6371009, 'KM': 6371.009, 'MI': 3958.761, 'NM': 3440.070, 'YD': 6967420, 'FT': 20902260};
53 if ( unit in r ) return r[unit];
54 else return unit;
55 },
56
57 distance: function(lat1, lon1, lat2, lon2, unit) {
58 if ( unit === undefined ) unit = 'KM';
59 var r = this.validateRadius(unit);
60 lat1 *= Math.PI / 180;
61 lon1 *= Math.PI / 180;
62 lat2 *= Math.PI / 180;
63 lon2 *= Math.PI / 180;
64 var lonDelta = lon2 - lon1;
65 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);
66 var b = Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(lonDelta);
67 var angle = Math.atan2(Math.sqrt(a) , b);
68
69 return angle * r;
70 },
71
72 bearing: function(lat1, lon1, lat2, lon2) {
73 lat1 *= Math.PI / 180;
74 lon1 *= Math.PI / 180;
75 lat2 *= Math.PI / 180;
76 lon2 *= Math.PI / 180;
77 var lonDelta = lon2 - lon1;
78 var y = Math.sin(lonDelta) * Math.cos(lat2);
79 var x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(lonDelta);
80 var brng = Math.atan2(y, x);
81 brng = brng * (180 / Math.PI);
82
83 if ( brng < 0 ) { brng += 360; }
84
85 return brng;
86 },
87
88 destination: function(lat1, lon1, brng, dt, unit) {
89 if ( unit === undefined ) unit = 'KM';
90 var r = this.validateRadius(unit);
91 lat1 *= Math.PI / 180;
92 lon1 *= Math.PI / 180;
93 var lat3 = Math.asin(Math.sin(lat1) * Math.cos(dt / r) + Math.cos(lat1) * Math.sin(dt / r) * Math.cos( brng * Math.PI / 180 ));
94 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));
95
96 return {
97 'LAT': lat3 * 180 / Math.PI,
98 'LON': lon3 * 180 / Math.PI
99 };
100 }
101
102}
103
104if (typeof module != 'undefined' && module.exports) {
105 module.exports = GreatCircle;
106} else {
107 window['GreatCircle'] = GreatCircle;
108}
109
110},{}]},{},[1]);
111</script>
112</html>
113

Built with git-ssb-web