-
Notifications
You must be signed in to change notification settings - Fork 236
Expand file tree
/
Copy pathuser.html
More file actions
63 lines (57 loc) · 2.49 KB
/
Copy pathuser.html
File metadata and controls
63 lines (57 loc) · 2.49 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nearby Hospitals List</title>
<link rel="stylesheet" href="user.css">
</head>
<body>
<div class="container">
<h1>Nearby Hospitals</h1>
<div id="hospitalList">
<!-- Hospital list will be populated by JavaScript -->
</div>
<button id="viewMapBtn">View on Map</button>
</div>
<script>
function fetchHospitalList() {
// Default location for the example
const defaultLocation = { lat: 28.7041, lng: 77.1025 }; // Example location
// Create a Google Maps PlacesService object
const service = new google.maps.places.PlacesService(document.createElement('div'));
// Define the request object
const request = {
location: defaultLocation,
radius: '5000', // Radius in meters
type: ['hospital'] // Search for hospitals
};
// Perform the search
service.nearbySearch(request, (results, status) => {
if (status === google.maps.places.PlacesServiceStatus.OK) {
const hospitalList = document.getElementById('hospitalList');
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);
}
});
}
// Initialize the hospital list when the page loads
window.onload = fetchHospitalList;
// Redirect to map page
document.getElementById('viewMapBtn').addEventListener('click', () => {
window.location.href = 'user-map.html';
});
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCKR3agIMLtauzDhz4fCu3heww0BV_81H4"></script>
</body>
</html>