Edoruin commited on
Commit
8fc8282
·
1 Parent(s): c4d2ccb

feat: hide GPS UI and move geocoding to GAS (Google Maps API)

Browse files
static/js/components/capture-form.js CHANGED
@@ -18,17 +18,8 @@ const CaptureFormComponent = {
18
  </div>
19
 
20
  <div class="content">
21
- <div class="card">
22
- <div style="display: flex; justify-content: space-between; align-items: center;">
23
- <h3>📍 Ubicación GPS</h3>
24
- <button class="btn-secondary" onclick="CaptureFormComponent.init()" style="padding: 5px 10px; font-size: 0.8rem; margin: 0;">
25
- 🔄 Actualizar
26
- </button>
27
- </div>
28
- <p id="location-status">Obteniendo ubicación...</p>
29
- <p id="location-accuracy" style="font-size: 0.8rem; color: #666;"></p>
30
- <p id="address-status" style="font-size: 0.9rem; color: #1e88e5; margin-top: 5px; font-weight: 500;"></p>
31
- </div>
32
 
33
  <form id="capture-form" onsubmit="CaptureFormComponent.submit(event)">
34
  <!-- Datos Simplificados -->
@@ -127,65 +118,12 @@ const CaptureFormComponent = {
127
  },
128
 
129
  async init() {
130
- const locationStatus = document.getElementById('location-status');
131
- const locationAccuracy = document.getElementById('location-accuracy');
132
- const addressStatus = document.getElementById('address-status');
133
-
134
- if (locationStatus) locationStatus.innerHTML = '⏳ Localizando...';
135
-
136
- // Get GPS location
137
  try {
138
  this.location = await geolocationService.getCurrentPosition();
139
-
140
- if (locationStatus) {
141
- locationStatus.innerHTML = `
142
- ✅ Ubicación obtenida<br>
143
- <small>Lat: ${this.location.latitude.toFixed(6)}, Lon: ${this.location.longitude.toFixed(6)}</small>
144
- `;
145
- }
146
-
147
- if (locationAccuracy) {
148
- const precision = Math.round(this.location.accuracy);
149
- let accuracyClass = 'accuracy-good';
150
- let warningMsg = '';
151
-
152
- if (precision > 500) {
153
- accuracyClass = 'accuracy-poor';
154
- warningMsg = '⚠️ <strong>Baja precisión:</strong> Estás usando ubicación por internet. Intenta salir a un lugar despejado para conectar con el GPS.';
155
- } else if (precision > 100) {
156
- accuracyClass = 'accuracy-medium';
157
- }
158
-
159
- locationAccuracy.innerHTML = `
160
- <span class="${accuracyClass}">Precisión: ±${precision} metros</span>
161
- <p style="font-size: 0.8rem; margin-top: 5px; color: #d32f2f;">${warningMsg}</p>
162
- `;
163
- }
164
-
165
- // Attempt reverse geocoding if online
166
- if (navigator.onLine) {
167
- if (addressStatus) addressStatus.innerText = 'Buscando nombre del lugar...';
168
-
169
- this.placeName = await geolocationService.getAddress(
170
- this.location.latitude,
171
- this.location.longitude
172
- );
173
-
174
- if (this.placeName && addressStatus) {
175
- addressStatus.innerHTML = `🏠 <strong>${this.placeName}</strong>`;
176
- } else if (addressStatus) {
177
- addressStatus.innerText = 'Lugar no identificado';
178
- }
179
- }
180
  } catch (error) {
181
- console.error('Error getting location:', error);
182
- if (locationStatus) {
183
- if (error.message.includes('Tiempo de espera')) {
184
- locationStatus.innerHTML = `❌ <strong>Tiempo agotado:</strong> El sensor GPS no responde.<br><small>Asegúrate de estar a cielo abierto y tener el GPS del celular encendido.</small>`;
185
- } else {
186
- locationStatus.innerHTML = `❌ Error: ${error.message}`;
187
- }
188
- }
189
  }
190
  },
191
 
@@ -197,20 +135,15 @@ const CaptureFormComponent = {
197
  async submit(event) {
198
  event.preventDefault();
199
 
200
- // One last quick check of location to ensure maximum accuracy before saving
201
  try {
202
- const freshLocation = await geolocationService.getCurrentPosition();
203
- this.location = freshLocation;
204
- // Optionally update placeName again if we have time/connection
205
- if (navigator.onLine) {
206
- this.placeName = await geolocationService.getAddress(this.location.latitude, this.location.longitude);
207
- }
208
  } catch (e) {
209
- console.warn('Final GPS refresh before submit failed, using previous value:', e);
210
  }
211
 
212
  if (!this.location) {
213
- alert('No se pudo obtener la ubicación GPS. Por favor, intenta de nuevo presionando "Actualizar" arriba.');
214
  return;
215
  }
216
 
 
18
  </div>
19
 
20
  <div class="content">
21
+ <div class="content">
22
+ <!-- Ubicación procesada en segundo plano -->
 
 
 
 
 
 
 
 
 
23
 
24
  <form id="capture-form" onsubmit="CaptureFormComponent.submit(event)">
25
  <!-- Datos Simplificados -->
 
118
  },
119
 
120
  async init() {
121
+ console.log('Capturando ubicación en segundo plano...');
 
 
 
 
 
 
122
  try {
123
  this.location = await geolocationService.getCurrentPosition();
124
+ console.log('Ubicación obtenida con éxito (silenciosa)');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  } catch (error) {
126
+ console.warn('Error capturando ubicación inicial:', error);
 
 
 
 
 
 
 
127
  }
128
  },
129
 
 
135
  async submit(event) {
136
  event.preventDefault();
137
 
138
+ // Refresco silencioso de GPS al enviar
139
  try {
140
+ this.location = await geolocationService.getCurrentPosition();
 
 
 
 
 
141
  } catch (e) {
142
+ console.warn('Refresh GPS falló, usando último valor conocido:', e);
143
  }
144
 
145
  if (!this.location) {
146
+ alert('Asegúrate de permitir el acceso al GPS para continuar. Es necesario para el registro científico.');
147
  return;
148
  }
149