CoolFace
Apppublic

tnemukula/transitpulse-navigator

sourceHugging Faceupdated 8mo agoView on Hugging Face
0likes
script.js70 linesDownload Raw Back to root
1// Main application logic2document.addEventListener('DOMContentLoaded', () => {3    // Current location functionality4    const getCurrentLocation = () => {5        if (navigator.geolocation) {6            navigator.geolocation.getCurrentPosition(7                (position) => {8                    console.log("Current position:", position.coords);9                    // In a real app, we would use this to center the map10                },11                (error) => {12                    console.error("Error getting location:", error);13                }14            );15        } else {16            console.log("Geolocation is not supported by this browser.");17        }18    };19 20    // Get location when user clicks on location icon21    document.addEventListener('click', (e) => {22        if (e.target.closest('[data-action="get-location"]')) {23            getCurrentLocation();24        }25    });26    // Function for route search with map integration27    window.searchRoutes = async (from, to) => {28        console.log(`Searching routes from ${from} to ${to}`);29        30        // In a real app, you would geocode the locations and fetch real transit data31        // For demo purposes, we'll use mock data with coordinates32        const mockRoutes = [33            {34                id: 1,35                from,36                to,37                duration: '15 min',38                changes: 1,39                distance: '3.2 km',40                fromCoords: [-74.0060, 40.7128], // NYC coordinates41                toCoords: [-74.0113, 40.7069],   // Nearby NYC coordinates42                steps: [43                    { type: 'walk', duration: '3 min', details: 'Walk to Central Station' },44                    { type: 'bus', duration: '8 min', details: 'Bus 42 to Downtown' },45                    { type: 'walk', duration: '4 min', details: 'Walk to destination' }46                ]47            }48        ];49 50        // Add markers to map51        if (window.addRouteMarkers) {52            window.addRouteMarkers(mockRoutes[0].fromCoords, mockRoutes[0].toCoords);53        }54 55        return mockRoutes;56    };57 58    // Connect search button to map59    document.addEventListener('click', async (e) => {60        if (e.target.closest('#search-button')) {61            const fromInput = document.querySelector('#from-input');62            const toInput = document.querySelector('#to-input');63            64            if (fromInput.value && toInput.value) {65                const routes = await searchRoutes(fromInput.value, toInput.value);66                console.log('Found routes:', routes);67            }68        }69    });70});