Control de Vehículos body { font-family: Arial, sans-serif; padding: 10px; background-color: #f4f4f4; } .vehiculo { border: 2px solid #333; border-radius: 10px; padding: 15px; margin-bottom: 20px; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,0.1); } .vehiculo h2 { margin: 0 0 10px; } button { margin: 5px 0; padding: 10px; font-size: 14px; width: 100%; } .log { background: #eaeaea; padding: 10px; font-size: 13px; margin-top: 10px; border-radius: 5px; }

Registro de Vehículos

const patentes = ['TL-XY-97', 'SF-VX-68', 'SF-VX-24', 'GH3456', 'IJ7890']; const datos = {}; function crearInterfaz() { const container = document.getElementById('container'); patentes.forEach(patente => { datos[patente] = []; const div = document.createElement('div'); div.className = 'vehiculo'; div.innerHTML = `

Vehículo: ${patente}

Sin registros.
`; container.appendChild(div); }); } async function obtenerDireccion(lat, lon) { const url = `https://nominatim.openstreetmap.org/reverse?lat=${lat}&lon=${lon}&format=json`; try { const response = await fetch(url, { headers: { 'User-Agent': 'vehiculo-app/1.0' } }); const data = await response.json(); return data.display_name || 'Dirección no disponible'; } catch (e) { return 'Dirección no disponible'; } } function registrar(patente, tipo) { navigator.geolocation.getCurrentPosition(async pos => { const now = new Date(); const lat = pos.coords.latitude.toFixed(6); const lon = pos.coords.longitude.toFixed(6); const direccion = await obtenerDireccion(lat, lon); const info = { fecha: now.toLocaleDateString(), hora: now.toLocaleTimeString(), coords: `${lat}, ${lon}`, direccion: direccion }; let viajes = datos[patente]; if (tipo === 'origen') { viajes.push({ origen: info }); } else if (tipo === 'destino') { let ultimo = viajes[viajes.length - 1]; if (ultimo && !ultimo.destino) { ultimo.destino = info; } else { alert("Primero debes registrar el origen."); return; } } actualizarLog(patente); }, err => { alert("Error obteniendo ubicación. Verifica permisos."); }); } function actualizarLog(patente) { const log = document.getElementById(`log-${patente}`); const viajes = datos[patente]; if (viajes.length === 0) { log.innerText = 'Sin registros.'; return; } log.innerHTML = viajes.map((v, i) => ` Viaje ${i + 1}
Origen: ${v.origen.fecha} ${v.origen.hora} (${v.origen.coords})
Dirección: ${v.origen.direccion}
Destino: ${v.destino ? `${v.destino.fecha} ${v.destino.hora} (${v.destino.coords})
Dirección: ${v.destino.direccion}` : '—'}
`).join(''); } async function generarPDF(patente) { const { jsPDF } = window.jspdf; const doc = new jsPDF(); const viajes = datos[patente]; doc.setFontSize(14); doc.text("Registro Diario - Vehículo: " + patente, 20, 20); let y = 30; viajes.forEach((v, i) => { doc.setFontSize(11); doc.text(`Viaje ${i + 1}`, 20, y); doc.text(`Origen: ${v.origen.fecha} ${v.origen.hora}`, 25, y + 6); doc.text(`Coords: ${v.origen.coords}`, 25, y + 12); doc.text(`Dirección: ${v.origen.direccion.substring(0, 70)}`, 25, y + 18); if (v.destino) { doc.text(`Destino: ${v.destino.fecha} ${v.destino.hora}`, 25, y + 24); doc.text(`Coords: ${v.destino.coords}`, 25, y + 30); doc.text(`Dirección: ${v.destino.direccion.substring(0, 70)}`, 25, y + 36); y += 46; } else { y += 24; } }); doc.save(`vehiculo_${patente}_registro.pdf`); } window.onload = crearInterfaz;