-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
84 lines (81 loc) · 2.5 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Traffic Tracking</title>
<link rel="stylesheet" href="style.css">
<div class="container" style="margin-bottom: 1.5rem">
<nav>
<ul class="menu">
<li><a href="index.html">Traffic Tracking</a></li>
<li><a href="about.html">About</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
<div class="search-bar" id="basic-bar">
<form action="">
<input
class="typeahead"
id="pac-input"
type="text"
placeholder="Enter a City Name"
>
</form>
</div>
</nav>
</div>
</head>
<body>
<div class="container">
<style>
/* Set the size of the map */
#map {
height: 600px;
width: 80%;
margin: 0 auto;
border: 1px solid #000;
border-radius: 25px;
}
</style>
<div id="map"></div>
<script async>
// Initialize and display the map
function initMap() {
var geocoder = new google.maps.Geocoder();
var input = document.getElementById("pac-input");
map = new google.maps.Map(document.getElementById("map"), {
center: { lat: -33.8688, lng: 151.2093 },
zoom: 12,
});
var city = "Sydney";
input.addEventListener("keydown", function (event) {
// detect event key
if (event.keyCode == 13) {
city = input.value;
input.value = "";
if (city == "") {
input = "Sydney";
}
geocoder.geocode({ address: city }, function (results, status) {
if (status === "OK") {
map.setCenter(results[0].geometry.location);
} else {
alert(
"The location doesn't exist, please try again!" + status
);
}
});
}
});
// Add the TrafficLayer to the map to display traffic information
var trafficLayer = new google.maps.TrafficLayer();
trafficLayer.setMap(map);
}
</script>
<script
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAvzkIdApps-fFm5O8a3Xn0jrxp1ctZD54&callback=initMap"
async
></script>
</div>
</body>
</html>