File size: 15,139 Bytes
1843c7f
 
 
 
 
 
 
 
 
 
 
 
 
 
29393ea
 
 
 
1843c7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29393ea
1843c7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37edede
 
 
 
 
1843c7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37edede
 
 
1843c7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37edede
 
 
 
 
 
 
 
 
1843c7f
37edede
 
 
 
 
 
29393ea
1843c7f
37edede
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1843c7f
37edede
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1843c7f
37edede
 
1843c7f
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Location Finder</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
    <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
    <style>
        #map {
            height: 400px;
            transition: all 0.3s ease;
        }
        #beachTideInfo {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
        .location-card {
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
        }
        .pulse {
            animation: pulse 2s infinite;
        }
        @keyframes pulse {
            0% {
                transform: scale(0.95);
                box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.7);
            }
            70% {
                transform: scale(1);
                box-shadow: 0 0 0 10px rgba(74, 222, 128, 0);
            }
            100% {
                transform: scale(0.95);
                box-shadow: 0 0 0 0 rgba(74, 222, 128, 0);
            }
        }
    </style>
</head>
<body class="bg-gray-50 min-h-screen">
    <div class="container mx-auto px-4 py-8">
        <div class="max-w-3xl mx-auto">
            <div class="text-center mb-8">
                <h1 class="text-4xl font-bold text-gray-800 mb-2">📍 Location Finder</h1>
                <p class="text-gray-600">Enter any address or place to see it on the map</p>
            </div>

            <div class="location-card bg-white rounded-xl p-6">
                <div class="flex flex-col md:flex-row gap-4">
                    <div class="flex-grow">
                        <label for="locationInput" class="block text-sm font-medium text-gray-700 mb-1">Search Location</label>
                        <div class="relative">
                            <input 
                                type="text" 
                                id="locationInput" 
                                placeholder="e.g. Eiffel Tower, Paris" 
                                class="w-full px-4 py-3 rounded-lg border border-gray-300 focus:ring-2 focus:ring-green-500 focus:border-green-500 transition"
                            >
                            <button 
                                id="searchButton" 
                                class="absolute right-2 top-1/2 transform -translate-y-1/2 bg-green-500 hover:bg-green-600 text-white p-2 rounded-lg transition duration-200 pulse"
                            >
                                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
                                    <path fill-rule="evenodd" d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z" clip-rule="evenodd" />
                                </svg>
                            </button>
                        </div>
                    </div>
                </div>
            </div>

            <div class="location-card bg-white rounded-xl overflow-hidden">
                <div id="map" class="w-full"></div>
                <div id="locationInfo" class="p-4 border-t border-gray-200 hidden">
                    <h3 class="font-semibold text-lg text-gray-800 mb-1">Location Details</h3>
                    <p id="address" class="text-gray-600"></p>
                    <p id="coordinates" class="text-sm text-gray-500 mt-1"></p>
                </div>
            </div>

            <div id="tideInfo" class="location-card bg-white rounded-xl p-6 mt-6 hidden">
                <h3 class="font-semibold text-lg text-gray-800 mb-4">Tide Information</h3>
                <div id="tideChart" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4"></div>
            </div>

            <div class="mt-6 text-center text-gray-500 text-sm">
                <p>Click the search button or press Enter to find your location</p>
            </div>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // Initialize map with a default view
            const map = L.map('map').setView([51.505, -0.09], 13);
            
            // Add tile layer (OpenStreetMap)
            L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
                attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
            }).addTo(map);
            
            // Create a marker but don't add it to the map yet
            let marker = null;
            
            // Function to update the map with the searched location
            function updateMap(location) {
                // Use Nominatim API for geocoding
                fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(location)}`)
                    .then(response => response.json())
                    .then(data => {
                        if (data.length > 0) {
                            const lat = parseFloat(data[0].lat);
                            const lon = parseFloat(data[0].lon);
                            const displayName = data[0].display_name;
                            
                            // Update map view
                            map.setView([lat, lon], 15);
                            
                            // Remove previous marker if exists
                            if (marker) {
                                map.removeLayer(marker);
                            }
                            
                            // Add new marker with custom icon
                            const customIcon = L.icon({
                                iconUrl: 'https://cdn0.iconfinder.com/data/icons/small-n-flat/24/678111-map-marker-512.png',
                                iconSize: [32, 32],
                                iconAnchor: [16, 32],
                                popupAnchor: [0, -32]
                            });
                            
                            marker = L.marker([lat, lon], {icon: customIcon}).addTo(map)
                                .bindPopup(displayName)
                                .openPopup();
                            
                            // Show location info
                            document.getElementById('locationInfo').classList.remove('hidden');
                            document.getElementById('address').textContent = displayName;
                            document.getElementById('coordinates').textContent = `Latitude: ${lat.toFixed(6)}, Longitude: ${lon.toFixed(6)}`;

                            // Check if location is near coast and get tide data
                            getTideData(lat, lon);
                            
                        } else {
                            alert('Location not found. Please try a different search term.');
                        }
                    })
                    .catch(error => {
                        console.error('Error:', error);
                        alert('There was an error processing your request. Please try again.');
                    });
            }
            
            // Search button click event
            document.getElementById('searchButton').addEventListener('click', function() {
                const location = document.getElementById('locationInput').value.trim();
                if (location) {
                    updateMap(location);
                } else {
                    alert('Please enter a location to search.');
                }
            });
            
            // Enter key press event
            document.getElementById('locationInput').addEventListener('keypress', function(e) {
                if (e.key === 'Enter') {
                    const location = document.getElementById('locationInput').value.trim();
                    if (location) {
                        updateMap(location);
                    } else {
                        alert('Please enter a location to search.');
                    }
                }
            });
            // Function to get tide data from NOAA API
            function getTideData(lat, lon) {
                // First get the nearest tide station
                fetch(`https://api.tidesandcurrents.noaa.gov/mdapi/prod/webapi/stations.json?type=tidepredictions&units=metric`)
                    .then(response => response.json())
                    .then(data => {
                        // Find nearest station
                        let nearestStation = null;
                        let minDistance = Infinity;
                        
                        data.stations.forEach(station => {
                            if (station.lat && station.lng) {
                                const distance = getDistance(lat, lon, parseFloat(station.lat), parseFloat(station.lng));
                                if (distance < minDistance && distance < 100) { // Within 100km
                                    minDistance = distance;
                                    nearestStation = station;
                                }
                            }
                        });

                        if (nearestStation) {
                            // Get tide predictions for next 7 days
                            const today = new Date();
                            const endDate = new Date();
                            endDate.setDate(today.getDate() + 7);
                            
                            const dateFormat = (d) => d.toISOString().split('T')[0];
                            const stationId = nearestStation.id;
                            
                            fetch(`https://api.tidesandcurrents.noaa.gov/api/prod/datagetter?product=predictions&application=NOS.COOPS.TAC.WL&begin_date=${dateFormat(today)}&end_date=${dateFormat(endDate)}&datum=MLLW&station=${stationId}&time_zone=lst_ldt&units=english&interval=hilo&format=json`)
                                .then(response => response.json())
                                .then(tideData => {
                                    displayTideData(tideData, nearestStation.name);
                                })
                                .catch(error => {
                                    console.error('Tide data error:', error);
                                });
                        } else {
                            document.getElementById('tideInfo').classList.add('hidden');
                        }
                    })
                    .catch(error => {
                        console.error('Station data error:', error);
                    });
            }

            // Helper function to calculate distance between coordinates
            function getDistance(lat1, lon1, lat2, lon2) {
                const R = 6371; // Earth radius in km
                const dLat = (lat2 - lat1) * Math.PI / 180;
                const dLon = (lon2 - lon1) * Math.PI / 180;
                const a = 
                    Math.sin(dLat/2) * Math.sin(dLat/2) +
                    Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) * 
                    Math.sin(dLon/2) * Math.sin(dLon/2);
                const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
                return R * c;
            }

            // Function to display tide data
            function displayTideData(tideData, stationName) {
                const tideContainer = document.getElementById('tideChart');
                tideContainer.innerHTML = '';
                
                if (tideData.predictions && tideData.predictions.length > 0) {
                    document.getElementById('tideInfo').classList.remove('hidden');
                    
                    // Group predictions by date
                    const predictionsByDate = {};
                    tideData.predictions.forEach(prediction => {
                        const date = prediction.t.split(' ')[0];
                        if (!predictionsByDate[date]) {
                            predictionsByDate[date] = [];
                        }
                        predictionsByDate[date].push(prediction);
                    });

                    // Create cards for each date
                    for (const date in predictionsByDate) {
                        const predictions = predictionsByDate[date];
                        const dateObj = new Date(date);
                        const dayName = dateObj.toLocaleDateString('en-US', { weekday: 'long' });
                        const formattedDate = dateObj.toLocaleDateString('en-US', { month: 'short', day: 'numeric' });
                        
                        const card = document.createElement('div');
                        card.className = 'bg-gray-50 p-4 rounded-lg';
                        card.innerHTML = `
                            <h4 class="font-medium text-gray-700 mb-2">${dayName}<br><span class="text-sm text-gray-500">${formattedDate}</span></h4>
                            <div class="space-y-2">
                                ${predictions.map(p => `
                                    <div class="flex justify-between items-center">
                                        <span class="text-sm ${p.type === 'H' ? 'text-blue-600' : 'text-amber-600'} font-medium">
                                            ${p.type === 'H' ? 'High' : 'Low'} Tide
                                        </span>
                                        <span class="text-sm text-gray-700">${p.t.split(' ')[1]}</span>
                                        <span class="text-sm font-medium">${p.v} ft</span>
                                    </div>
                                `).join('')}
                            </div>
                        `;
                        tideContainer.appendChild(card);
                    }
                } else {
                    document.getElementById('tideInfo').classList.add('hidden');
                }
            }
        });
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=mirthbottle/activities-planner" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>