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