gmaps
This commit is contained in:
parent
10316b3644
commit
23725f3016
2
db/migrate.php
Normal file
2
db/migrate.php
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/migrations/001_create_restaurants_table.php';
|
||||||
20
db/migrations/001_create_restaurants_table.php
Normal file
20
db/migrations/001_create_restaurants_table.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/../config.php';
|
||||||
|
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$sql = "
|
||||||
|
CREATE TABLE IF NOT EXISTS restaurants (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
name VARCHAR(255) NOT NULL,
|
||||||
|
latitude DECIMAL(10, 8) NOT NULL,
|
||||||
|
longitude DECIMAL(11, 8) NOT NULL,
|
||||||
|
description TEXT
|
||||||
|
);
|
||||||
|
";
|
||||||
|
$pdo->exec($sql);
|
||||||
|
echo "Migration successful: 'restaurants' table created or already exists.\n";
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
die("Migration failed: " . $e->getMessage() . "\n");
|
||||||
|
}
|
||||||
|
|
||||||
2
db/seed.php
Normal file
2
db/seed.php
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/seeds/001_seed_restaurants.php';
|
||||||
48
db/seeds/001_seed_restaurants.php
Normal file
48
db/seeds/001_seed_restaurants.php
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/../config.php';
|
||||||
|
|
||||||
|
$restaurants = [
|
||||||
|
[
|
||||||
|
'name' => 'Bonito',
|
||||||
|
'latitude' => 38.716842,
|
||||||
|
'longitude' => -9.140232,
|
||||||
|
'description' => 'A cozy place with great seafood.'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'D\'Bacalhau',
|
||||||
|
'latitude' => 38.711963,
|
||||||
|
'longitude' => -9.133382,
|
||||||
|
'description' => 'The best codfish in town.'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Tasca do Chico',
|
||||||
|
'latitude' => 38.714244,
|
||||||
|
'longitude' => -9.143634,
|
||||||
|
'description' => 'Live Fado music and traditional food.'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Solar dos Presuntos',
|
||||||
|
'latitude' => 38.717889,
|
||||||
|
'longitude' => -9.14299,
|
||||||
|
'description' => 'Famous for its fresh seafood and lively atmosphere.'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Cervejaria Ramiro',
|
||||||
|
'latitude' => 38.719931,
|
||||||
|
'longitude' => -9.139225,
|
||||||
|
'description' => 'A legendary seafood restaurant.'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO restaurants (name, latitude, longitude, description) VALUES (:name, :latitude, :longitude, :description)");
|
||||||
|
|
||||||
|
foreach ($restaurants as $restaurant) {
|
||||||
|
$stmt->execute($restaurant);
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "Seeding successful: " . count($restaurants) . " restaurants inserted.\n";
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
die("Seeding failed: " . $e->getMessage() . "\n");
|
||||||
|
}
|
||||||
84
index.php
84
index.php
@ -1,12 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'db/config.php';
|
||||||
|
|
||||||
|
try {
|
||||||
|
$pdo = db();
|
||||||
|
$stmt = $pdo->query('SELECT name, latitude, longitude, description FROM restaurants');
|
||||||
|
$restaurants = $stmt->fetchAll();
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
// For development, you might want to log this error.
|
||||||
|
// For production, you could show a generic error message.
|
||||||
|
error_log('Database error: ' . $e->getMessage());
|
||||||
|
$restaurants = []; // Ensure restaurants is an empty array on error
|
||||||
|
}
|
||||||
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>WebSummit Restaurants Map</title>
|
<title>WebSummit Restaurants Map</title>
|
||||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
|
|
||||||
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
|
|
||||||
crossorigin=""/>
|
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
@ -21,41 +32,50 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="map"></div>
|
<div id="map"></div>
|
||||||
|
|
||||||
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"
|
|
||||||
integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo="
|
|
||||||
crossorigin=""></script>
|
|
||||||
<script>
|
<script>
|
||||||
var map = L.map('map').setView([38.7686, -9.0940], 15);
|
const restaurants = <?php echo json_encode($restaurants, JSON_NUMERIC_CHECK); ?>;
|
||||||
|
|
||||||
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
function initMap() {
|
||||||
maxZoom: 19,
|
const webSummitLocation = { lat: 38.7686, lng: -9.0940 };
|
||||||
attribution: '© OpenStreetMap'
|
const map = new google.maps.Map(document.getElementById("map"), {
|
||||||
}).addTo(map);
|
zoom: 15,
|
||||||
|
center: webSummitLocation,
|
||||||
|
});
|
||||||
|
|
||||||
var webSummitIcon = L.icon({
|
const webSummitMarker = new google.maps.Marker({
|
||||||
iconUrl: 'https://img.icons8.com/color/48/000000/filled-star.png',
|
position: webSummitLocation,
|
||||||
iconSize: [48, 48],
|
map: map,
|
||||||
iconAnchor: [24, 48],
|
icon: 'https://img.icons8.com/color/48/000000/filled-star.png',
|
||||||
popupAnchor: [0, -48]
|
title: "Web Summit @ MEO Arena"
|
||||||
});
|
});
|
||||||
|
|
||||||
var webSummitMarker = L.marker([38.7686, -9.0940], {icon: webSummitIcon}).addTo(map);
|
const infoWindow = new google.maps.InfoWindow();
|
||||||
webSummitMarker.bindPopup("<b>Web Summit @ MEO Arena</b>").openPopup();
|
|
||||||
|
|
||||||
const restaurants = [
|
webSummitMarker.addListener('click', () => {
|
||||||
{ name: 'Cantinho do Avillez', lat: 38.77, lng: -9.095 },
|
infoWindow.setContent("<b>Web Summit @ MEO Arena</b>");
|
||||||
{ name: 'Senhor Peixe', lat: 38.765, lng: -9.092 },
|
infoWindow.open(map, webSummitMarker);
|
||||||
{ name: 'D\'Bacalhau', lat: 38.769, lng: -9.098 },
|
});
|
||||||
{ name: 'The Old House', lat: 38.767, lng: -9.091 },
|
|
||||||
{ name: 'ZeroZero Pizzeria', lat: 38.771, lng: -9.096 },
|
|
||||||
{ name: 'Butchers', lat: 38.766, lng: -9.099 },
|
|
||||||
{ name: 'Honorato', lat: 38.764, lng: -9.093 }
|
|
||||||
];
|
|
||||||
|
|
||||||
restaurants.forEach(restaurant => {
|
restaurants.forEach(restaurant => {
|
||||||
var marker = L.marker([restaurant.lat, restaurant.lng]).addTo(map);
|
const marker = new google.maps.Marker({
|
||||||
marker.bindPopup(`<b>${restaurant.name}</b>`);
|
position: { lat: restaurant.latitude, lng: restaurant.longitude },
|
||||||
});
|
map: map,
|
||||||
|
title: restaurant.name
|
||||||
|
});
|
||||||
|
|
||||||
|
marker.addListener('click', () => {
|
||||||
|
let content = `<b>${restaurant.name}</b>`;
|
||||||
|
if (restaurant.description) {
|
||||||
|
content += `<br>${restaurant.description}`;
|
||||||
|
}
|
||||||
|
infoWindow.setContent(content);
|
||||||
|
infoWindow.open(map, marker);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<script async defer
|
||||||
|
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCzZ8gdqKEbb2BaQxSeccfE97wjfl46Ruw&callback=initMap">
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user