forked from mansiruhil/AmbuFlow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser-map.html
78 lines (71 loc) · 3.27 KB
/
user-map.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
75
76
77
78
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hospital on Map</title>
<link rel="stylesheet" href="src/css/user-map.css">
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCKR3agIMLtauzDhz4fCu3heww0BV_81H4&libraries=places"></script>
</head>
<body>
<div class="container">
<h1>Hospitals</h1>
<div id="map" style="height: 500px; width: 100%;"></div>
<button id="viewListBtn">Back to List</button>
</div>
<script>
function initMap() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
const userLocation = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
const map = new google.maps.Map(document.getElementById("map"), {
center: userLocation,
zoom: 14
});
const service = new google.maps.places.PlacesService(map);
const request = {
location: userLocation,
radius: '5000',
type: ['hospital', 'pharmacy']
};
service.nearbySearch(request, (results, status) => {
if (status === google.maps.places.PlacesServiceStatus.OK) {
results.forEach(place => {
const marker = new google.maps.Marker({
map: map,
position: place.geometry.location,
title: place.name
});
const infoWindow = new google.maps.InfoWindow();
google.maps.event.addListener(marker, 'click', () => {
infoWindow.setContent(`
<div>
<h3>${place.name}</h3>
<p><strong>Address:</strong> ${place.vicinity}</p>
<p><strong>Rating:</strong> ${place.rating ? place.rating : 'No rating'}</p>
</div>
`);
infoWindow.open(map, marker);
});
});
} 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 = initMap;
document.getElementById('viewListBtn').addEventListener('click', () => {
window.location.href = 'user.html';
});
</script>
</body>
</html>