-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdaflsdf.html
119 lines (98 loc) · 3.29 KB
/
daflsdf.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hackathon</title>
<style>
/* container to center map */
#containter{
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
#map{
height: 80vh;
width: 80vw;
}
html, body{
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="container">
<div id="map"></div>
</div>
<script>
// Note: This example requires that you consent to location sharing when
// prompted by your browser. If you see the error "The Geolocation service
// failed.", it means you probably did not give permission for the browser to
// locate you.
let map, infoWindow;
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
center: { lat: 37.3541, lng: -121.9552 },
zoom: 13,
});
new google.maps.Marker({
position: {lat: 37.3541, lng: -121.9552},
map,
title: "Hello World!",
});
new google.maps.Marker({
position: {lat: 37.4541, lng: -121.9552},
map,
title: "Hello World!",
});
new google.maps.Marker({
position: {lat: 37.6541, lng: -121.9552},
map,
title: "Hello World!",
});
infoWindow = new google.maps.InfoWindow();
const locationButton = document.createElement("button");
locationButton.textContent = "Find current location";
locationButton.classList.add("custom-map-control-button");
map.controls[google.maps.ControlPosition.TOP_CENTER].push(locationButton);
locationButton.addEventListener("click", () => {
// Try HTML5 geolocation.
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
(position) => {
const pos = {
lat: position.coords.latitude,
lng: position.coords.longitude,
};
infoWindow.setPosition(pos);
infoWindow.setContent("You are here!");
infoWindow.open(map);
map.setCenter(pos);
},
() => {
handleLocationError(true, infoWindow, map.getCenter());
}
);
} else {
// Browser doesn't support Geolocation
handleLocationError(false, infoWindow, map.getCenter());
}
});
}
function handleLocationError(browserHasGeolocation, infoWindow, pos) {
infoWindow.setPosition(pos);
infoWindow.setContent(
browserHasGeolocation
? "Error: The Geolocation service failed."
: "Error: Your browser doesn't support geolocation."
);
infoWindow.open(map);
}
window.initMap = initMap;
</script>
<script src=" https://maps.googleapis.com/maps/api/js?key=AIzaSyD8De88P5fO7UrJX5KSt94ttAe794AyRNw&callback=initMap"></script>
</body>
</html>