forked from mansiruhil13/Bobble-AI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.html
74 lines (69 loc) · 3.2 KB
/
user.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nearby Hospitals</title>
<link rel="stylesheet" href="src/css/user.css">
<link href="/dist/output.css" rel="stylesheet">
<link rel="shortcut icon" href="ambulance.png" type="image/x-icon">
</head>
<body>
<div class="container">
<h1 class="text-4xl font-extrabold text-stone-900">Nearby Hospitals</h1>
<div id="hospitalList">
<div class="hospital-item">
<h3>Hospital Name</h3>
<p><strong>Address:</strong> Address</p>
<p><strong>Rating:</strong> 4.5</p>
</div>
</div>
<button id="viewMapBtn" class="">View on Map</button>
</div>
<script>
function fetchHospitalList() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
const userLocation = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
const service = new google.maps.places.PlacesService(document.createElement('div'));
const request = {
location: userLocation,
radius: '5000',
type: ['hospital', 'pharmacy']
};
service.nearbySearch(request, (results, status) => {
if (status === google.maps.places.PlacesServiceStatus.OK) {
const hospitalList = document.getElementById('hospitalList');
hospitalList.innerHTML = '';
results.forEach(place => {
const hospitalItem = document.createElement('div');
hospitalItem.className = 'hospital-item';
hospitalItem.innerHTML = `
<h3>${place.name}</h3>
<p><strong>Address:</strong> ${place.vicinity}</p>
<p><strong>Rating:</strong> ${place.rating ? place.rating : 'No rating'}</p>
`;
hospitalList.appendChild(hospitalItem);
});
} else {
console.error('Places request failed due to: ' + status);
}
});
}, error => {
console.error('Error getting user location: ' + error.message);
});
} else {
console.error('Geolocation is not supported by this browser.');
}
}
window.onload = fetchHospitalList;
document.getElementById('viewMapBtn').addEventListener('click', () => {
window.location.href = 'user-map.html';
});
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCKR3agIMLtauzDhz4fCu3heww0BV_81H4&libraries=places"></script>
</body>
</html>