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