|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <title>Travel Itinerary Planner</title> |
| 6 | + <style> |
| 7 | + body { font-family: Arial, sans-serif; margin: 40px; } |
| 8 | + .container { max-width: 700px; margin: auto; } |
| 9 | + input, button, textarea { margin: 5px; } |
| 10 | + textarea { width: 100%; height: 60px; } |
| 11 | + </style> |
| 12 | +</head> |
| 13 | +<body> |
| 14 | +<div class="container"> |
| 15 | + <h2>Travel Itinerary Planner</h2> |
| 16 | + <div> |
| 17 | + <label>Trip Name: </label> |
| 18 | + <input type="text" id="tripName" /> |
| 19 | + </div> |
| 20 | + <div> |
| 21 | + <label>Places to Visit (comma separated): </label> |
| 22 | + <input type="text" id="places" /> |
| 23 | + </div> |
| 24 | + <div> |
| 25 | + <label>Accommodations: </label> |
| 26 | + <input type="text" id="accommodations" /> |
| 27 | + </div> |
| 28 | + <div> |
| 29 | + <label>Activities: </label> |
| 30 | + <textarea id="activities"></textarea> |
| 31 | + </div> |
| 32 | + <button onclick="addItinerary()">Save Itinerary</button> |
| 33 | + <h3>Saved Itineraries</h3> |
| 34 | + <ul id="itineraryList"></ul> |
| 35 | + <h3>Map Preview</h3> |
| 36 | + <iframe id="mapFrame" width="600" height="400" style="border:0" allowfullscreen loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe> |
| 37 | +</div> |
| 38 | +<script> |
| 39 | +function addItinerary() { |
| 40 | + const trip = { |
| 41 | + name: document.getElementById('tripName').value, |
| 42 | + places: document.getElementById('places').value.split(','), |
| 43 | + accommodations: document.getElementById('accommodations').value, |
| 44 | + activities: document.getElementById('activities').value |
| 45 | + }; |
| 46 | + fetch('/api/itineraries', { |
| 47 | + method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(trip) |
| 48 | + }).then(fetchItineraries); |
| 49 | +} |
| 50 | +function fetchItineraries() { |
| 51 | + fetch('/api/itineraries').then(r => r.json()).then(data => { |
| 52 | + const list = document.getElementById('itineraryList'); |
| 53 | + list.innerHTML = ''; |
| 54 | + data.forEach((it, idx) => { |
| 55 | + const li = document.createElement('li'); |
| 56 | + li.innerHTML = `<b>${it.name}</b>: Places - ${it.places.join(', ')}, Accommodations - ${it.accommodations}, Activities - ${it.activities} <button onclick='showMap(${idx})'>Show Map</button>`; |
| 57 | + list.appendChild(li); |
| 58 | + }); |
| 59 | + }); |
| 60 | +} |
| 61 | +function showMap(idx) { |
| 62 | + fetch('/api/itineraries').then(r => r.json()).then(data => { |
| 63 | + const places = data[idx].places.map(p => encodeURIComponent(p.trim())).join('%2C'); |
| 64 | + const url = `https://www.google.com/maps/embed/v1/search?key=YOUR_API_KEY&q=${places}`; |
| 65 | + document.getElementById('mapFrame').src = url; |
| 66 | + }); |
| 67 | +} |
| 68 | +fetchItineraries(); |
| 69 | +</script> |
| 70 | +</body> |
| 71 | +</html> |
0 commit comments