-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
121 lines (87 loc) · 3.39 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
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
120
121
<!DOCTYPE html>
<html>
<head>
<script src="https://use.fontawesome.com/6279b68784.js"></script>
<link rel="stylesheet" type="text/css" href="index.css">
</head>
<body>
<div class="container">
<header>CONTACT</header>
<section>
<div class="view">
<div style="height:100%;" id="map">To LOAD THE MAP PLACE YOUR API IN API_KEY AREA</div>
<ul class="location">
<li>USA</li>
<li>INDIA</li>
<li>CHINA</li>
<li>JAPAN</li>
</ul>
</div>
<div class="form">
<div class="social">
<span>CONNECT</span>
<ul class="social-icons">
<li><i class="fa fa-facebook" aria-hidden="true"></i></li>
<li><i class="fa fa-twitter" aria-hidden="true"></i></li>
<li><i class="fa fa-linkedin" aria-hidden="true"></i></li>
<li><i class="fa fa-instagram" aria-hidden="true"></i></li>
<li><i class="fa fa-google-plus"></i></li>
</ul>
</div>
<hr>
<form action="#">
<span>SEND A MESSAGE</span>
<input type="text" name="email" value="Email">
<input type="text" name="email" value="Subject">
<textarea name="Message" id="message" value="Message" cols="30" rows="5">Message</textarea>
<button action="#" type="submit">Send</button>
</form>
<hr>
<div class="contact">
<span>OTHER WAY</span>
<i class="fa fa-inbox" aria-hidden="true">rkredux@gmail.com</i>
<i class="fa fa-phone" aria-hidden="true">202-909-6437</i>
<div/>
</div>
</section>
</div>
<script>
function myMap() {
const address = {
USA: "1701, 16th Street NW, Washington DC, 20009, USA",
INDIA: "B1/23, Safdarjung Enclave, New Delhi, 110029, India",
CHINA: "Peking University, Beijing, China",
JAPAN: "Osaka University, Osaka, Japan"
};
function getCoordinates(event){
// if li element is hightlighted replace
// it with the new li element that is active
// add a class and highlight the in focus li element.
const location = address[event.target.innerText].split(" ").join("+").trim();
// build query string
const query = `https://maps.googleapis.com/maps/api/geocode/json?address=${location}&key=API_KEY`;
// go ahead fetch it
fetch(query)
.then((response) => response.json())
.then(function (res){
return res.results[0].geometry.location;
})
.then((res) => { //build mapOptions object
const myLatLng = {lat: res.lat, lng: res.lng};
const map = new google.maps.Map(document.getElementById("map"), {
zoom: 4,
center: myLatLng
});
const marker = new google.maps.Marker({
position: myLatLng,
map,
title: "Hello World"
});
});
};
document.querySelectorAll("ul.location > li").forEach((elm) => elm.addEventListener("click", getCoordinates));
}
</script>
<script async src="https://maps.googleapis.com/maps/api/js?key="API_KEY"&callback=myMap"></script>
</body>
</html>