aboutsummaryrefslogtreecommitdiff
path: root/content/logger.html
diff options
context:
space:
mode:
Diffstat (limited to 'content/logger.html')
-rw-r--r--content/logger.html45
1 files changed, 23 insertions, 22 deletions
diff --git a/content/logger.html b/content/logger.html
index 1a6967e..4c0700a 100644
--- a/content/logger.html
+++ b/content/logger.html
@@ -28,6 +28,10 @@
28 <td id="value-longitude"></td> 28 <td id="value-longitude"></td>
29 </tr> 29 </tr>
30 <tr> 30 <tr>
31 <td>Accuracy</td>
32 <td id="value-accuracy"></td>
33 </tr>
34 <tr>
31 <td>Heading</td> 35 <td>Heading</td>
32 <td id="value-heading"></td> 36 <td id="value-heading"></td>
33 </tr> 37 </tr>
@@ -46,7 +50,7 @@
46 accuracy: 0, 50 accuracy: 0,
47 timestamp: 0, 51 timestamp: 0,
48 heading: 0, 52 heading: 0,
49 permissions: false, 53 setup: false,
50 inprogress: false, 54 inprogress: false,
51 }; 55 };
52 56
@@ -77,55 +81,52 @@
77 update_ui(); 81 update_ui();
78 } 82 }
79 83
80 function request_permissions() { 84 function logger_setup() {
81 if (DeviceOrientationEvent.requestPermission) { 85 if (DeviceOrientationEvent.requestPermission) {
82 DeviceOrientationEvent.requestPermission().then(() => { 86 DeviceOrientationEvent.requestPermission().then(() => {
83 window.addEventListener("deviceorientation", (event) => { 87 window.addEventListener("deviceorientation", (event) => {
84 logger_state.heading = event.webkitCompassHeading; 88 logger_state.heading = event.webkitCompassHeading;
85 update_ui(); 89 update_ui();
86 }); 90 });
87 logger_state.permissions = true;
88 log(); 91 log();
89 }).catch((err) => { 92 }).catch((err) => {
90 alert(`failed to get device orientation permissions: ${err}`) 93 alert(`failed to get device orientation permissions: ${err}`)
91 }) 94 })
92 } 95 }
93 }
94
95 function log() {
96 if (logger_state.inprogress)
97 return;
98
99 logger_state.latitude = null;
100 logger_state.longitude = null;
101 logger_state.accuracy = null;
102 logger_state.timestamp = null;
103 update_ui();
104
105 if (!logger_state.permissions) {
106 request_permissions();
107 return;
108 }
109 96
110 navigator.geolocation.getCurrentPosition((position) => { 97 navigator.geolocation.watchPosition((position) => {
111 console.log(position); 98 console.log(position);
112 logger_state.latitude = position.coords.latitude; 99 logger_state.latitude = position.coords.latitude;
113 logger_state.longitude = position.coords.longitude; 100 logger_state.longitude = position.coords.longitude;
114 logger_state.accuracy = position.coords.accuracy; 101 logger_state.accuracy = position.coords.accuracy;
115 logger_state.timestamp = position.timestamp; 102 logger_state.timestamp = position.timestamp;
116 update_ui(); 103 update_ui();
117 log_post();
118 }, (err) => { 104 }, (err) => {
119 alert(`failed to get position: ${err}`); 105 alert(`failed to get position: ${err}`);
120 }); 106 }, {enableHighAccuracy: true});
107
108
109 logger_state.setup = true;
110 }
111
112 function log() {
113 if (logger_state.inprogress)
114 return;
115
116 if (!logger_state.setup) {
117 logger_setup();
118 return;
119 }
121 120
122 logger_state.inprogress = true; 121 logger_state.inprogress = true;
122 log_post();
123 update_ui(); 123 update_ui();
124 } 124 }
125 125
126 function update_ui() { 126 function update_ui() {
127 set_table_value("value-latitude", logger_state.latitude); 127 set_table_value("value-latitude", logger_state.latitude);
128 set_table_value("value-longitude", logger_state.longitude); 128 set_table_value("value-longitude", logger_state.longitude);
129 set_table_value("value-accuracy", logger_state.accuracy);
129 set_table_value("value-heading", logger_state.heading); 130 set_table_value("value-heading", logger_state.heading);
130 131
131 const progress_display = logger_state.inprogress ? "block" : "none"; 132 const progress_display = logger_state.inprogress ? "block" : "none";