Okay, let's build a more interactive prototype using HTML, CSS, and JavaScript that you can test on an online compiler like CodePen, JSFiddle, or Replit. This will simulate the core map and user profile interaction.
Key Improvements in this Prototype:
- Simulated User Data: We'll use a JavaScript array to hold user data.
- Map Markers: Markers will be placed on the map based on user coordinates.
- Popup Profiles: Clicking a marker will display a popup with user information.
- Basic Styling: CSS for a cleaner look.
- No Backend: This is a frontend-only prototype.
Here's the code:
<!DOCTYPE html>
<html>
<head>
<title>Smoke Mates Finder - Prototype</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<style>
body { margin: 0; padding: 0; font-family: Arial, sans-serif; }
#map { height: 90vh; width: 100vw; }
.leaflet-popup-content { font-size: 16px; }
.user-card { margin: 0; padding: 10px; border: 1px solid #ccc; border-radius: 5px; }
.user-card img { width: 60px; height: 60px; border-radius: 50%; margin-right: 10px; }
.user-card h3 { margin: 5px 0; }
.user-card p { margin: 2px 0; }
</style>
</head>
<body>
<h2>Smoke Mates Finder (Prototype)</h2>
<div id="map"></div>
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script>
// Sample User Data
const users = [
{
name: "Alex",
age: 25,
bio: "Looking for a chill smoke mate in the park.",
lat: 40.7128,
lng: -74.0060,
photo: "https://randomuser.me/api/portraits/men/32.jpg"
},
{
name: "Sam",
age: 29,
bio: "Love to chat and smoke after work.",
lat: 40.7138,
lng: -74.0010,
photo: "https://randomuser.me/api/portraits/men/45.jpg"
},
{
name: "Jess",
age: 22,
bio: "New in town, looking for friends to smoke with.",
lat: 40.7108,
lng: -74.0080,
photo: "https://randomuser.me/api/portraits/women/65.jpg"
},
{
name: "Chris",
age: 31,
bio: "Enjoying a relaxing smoke session.",
lat: 40.7145,
lng: -73.9980,
photo: "https://randomuser.me/api/portraits/men/50.jpg"
}
];
// Initialize Map
const map = L.map('map').setView([40.7128, -74.0060], 14);
// Add Tile Layer (OpenStreetMap)
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
// Add User Markers
users.forEach(user => {
const marker = L.marker([user.lat, user.lng]).addTo(map);
marker.bindPopup(`
<div class="user-card">
<img src="${user.photo}" alt="${user.name}" />
<h3>${user.name}, ${user.age}</h3>
<p>${user.bio}</p>
</div>
`);
});
</script>
</body>
</html>
How to Test:
- Copy the Code: Copy the entire code block above.
- Online Compiler:
- Paste and Run: Paste the code into the HTML section of the online compiler and run it.
Explanation:
- Leaflet.js: We use Leaflet.js for the map functionality. It's a lightweight and easy-to-use library.
- User Data: The
users array holds the information for each user.
- Map Initialization:
L.map('map').setView(...) creates the map and sets the initial view.
- Tile Layer:
L.tileLayer(...) adds the map tiles (the visual map data) from OpenStreetMap.
- Markers: We loop through the
users array and create a marker for each user using L.marker(...).
- Popups:
marker.bindPopup(...) attaches a popup to each marker. The popup content is HTML that displays the user's information.
To make this more realistic, you would need to:
- Implement a Backend: Use a backend language (Node.js, Python, etc.) and a database to store user data.
- Real-Time Location Updates: Use WebSockets or a similar technology to update user locations in real-time.
- Authentication: Add user registration and login.
- Chat: Implement a chat feature.
- Privacy Controls: Allow users to control their privacy settings.
Let me know if you'd like me to help you with any of these more advanced features! I can provide code snippets or guidance.