Actualizar calendario.html
This commit is contained in:
@@ -507,29 +507,64 @@
|
|||||||
|
|
||||||
function callClient() { const p = document.getElementById('detPhoneRaw').value; if (p) window.location.href = `tel:+34${p}`; else alert("Sin teléfono"); }
|
function callClient() { const p = document.getElementById('detPhoneRaw').value; if (p) window.location.href = `tel:+34${p}`; else alert("Sin teléfono"); }
|
||||||
function openWhatsApp() { const p = document.getElementById('detPhoneRaw').value; if (p) window.open(`https://wa.me/34${p}`, '_blank'); else alert("Sin teléfono"); }
|
function openWhatsApp() { const p = document.getElementById('detPhoneRaw').value; if (p) window.open(`https://wa.me/34${p}`, '_blank'); else alert("Sin teléfono"); }
|
||||||
function openMaps() { const a = document.getElementById('detAddress').innerText; if (a) window.open(`maps://?q=${encodeURIComponent(a)}`, '_blank'); }
|
|
||||||
|
// BOTÓN VER MAPA CORREGIDO PARA ANDROID E IOS
|
||||||
|
function openMaps() {
|
||||||
|
const a = document.getElementById('detAddress').innerText;
|
||||||
|
if (a) {
|
||||||
|
window.open(`https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(a)}`, '_blank');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CÁLCULO DE GPS CORREGIDO CON FALLBACK Y MANEJO DE ERRORES
|
||||||
async function calculateDistance(dest) {
|
async function calculateDistance(dest) {
|
||||||
if(!navigator.geolocation) return;
|
const loading = document.getElementById('gpsLoading');
|
||||||
document.getElementById('gpsLoading').classList.remove('hidden');
|
const result = document.getElementById('gpsResult');
|
||||||
document.getElementById('gpsResult').classList.add('hidden');
|
|
||||||
|
if(!navigator.geolocation) {
|
||||||
|
loading.innerHTML = '<span class="text-[9px]">GPS Inactivo</span>';
|
||||||
|
lucide.createIcons();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
loading.classList.remove('hidden');
|
||||||
|
loading.innerHTML = '<i data-lucide="loader-2" class="w-3 h-3 animate-spin"></i> GPS...';
|
||||||
|
result.classList.add('hidden');
|
||||||
|
lucide.createIcons();
|
||||||
|
|
||||||
navigator.geolocation.getCurrentPosition(async (pos) => {
|
navigator.geolocation.getCurrentPosition(async (pos) => {
|
||||||
const lat = pos.coords.latitude; const lon = pos.coords.longitude;
|
const lat = pos.coords.latitude;
|
||||||
|
const lon = pos.coords.longitude;
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(dest + ', España')}`);
|
// Intento 1: Dirección completa
|
||||||
const data = await res.json();
|
let res = await fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(dest + ', España')}`);
|
||||||
if (data && data[0]) {
|
let data = await res.json();
|
||||||
|
|
||||||
|
// Intento 2: Si falla (porque hay "pisos", "escaleras", etc), buscamos solo por CP y Población
|
||||||
|
if (!data || data.length === 0) {
|
||||||
|
const parts = dest.split(',');
|
||||||
|
const fallbackDest = parts.length > 1 ? parts[parts.length - 1].trim() : dest;
|
||||||
|
res = await fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(fallbackDest + ', España')}`);
|
||||||
|
data = await res.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data && data.length > 0) {
|
||||||
const R = 6371; const dLat = (data[0].lat - lat) * Math.PI / 180; const dLon = (data[0].lon - lon) * Math.PI / 180;
|
const R = 6371; const dLat = (data[0].lat - lat) * Math.PI / 180; const dLon = (data[0].lon - lon) * Math.PI / 180;
|
||||||
const a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(lat * Math.PI / 180) * Math.cos(data[0].lat * Math.PI / 180) * Math.sin(dLon/2) * Math.sin(dLon/2);
|
const a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(lat * Math.PI / 180) * Math.cos(data[0].lat * Math.PI / 180) * Math.sin(dLon/2) * Math.sin(dLon/2);
|
||||||
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
|
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
|
||||||
const km = R * c;
|
const km = R * c;
|
||||||
document.getElementById('gpsLoading').classList.add('hidden');
|
loading.classList.add('hidden');
|
||||||
document.getElementById('gpsResult').classList.remove('hidden');
|
result.classList.remove('hidden');
|
||||||
document.getElementById('gpsKm').innerText = km.toFixed(1);
|
document.getElementById('gpsKm').innerText = km.toFixed(1);
|
||||||
document.getElementById('gpsMins').innerText = Math.round((km/35)*60)+5;
|
document.getElementById('gpsMins').innerText = Math.round((km/35)*60)+5;
|
||||||
|
} else {
|
||||||
|
loading.innerHTML = '<span class="text-[9px]">No calculable</span>';
|
||||||
}
|
}
|
||||||
} catch(e) { }
|
} catch(e) {
|
||||||
|
loading.innerHTML = '<span class="text-[9px]">Error de red</span>';
|
||||||
|
}
|
||||||
|
}, (err) => {
|
||||||
|
loading.innerHTML = '<span class="text-[9px]">Permiso GPS denegado</span>';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user