-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
84 lines (74 loc) · 2.14 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">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
#map{
height: 400px;
width: 100%;
}
</style>
</head>
<body>
<h1>My Google Map</h1>
<div id="map"></div>
<script>
function initMap(){
var options = {
zoom: 8,
center: { lat: 42.361145, lng: -71.057083}
}
var map = new google.maps.Map(document.getElementById('map'), options)
google.maps.event.addListener(map, 'click', function(event){
addMarker({position:event.latLng});
})
// var marker = new google.maps.Marker({
// position: { lat: 42.361145, lng: -71.057083 },
// map,
// icon: 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png'
// })
// var infoWindow = new google.maps.InfoWindow({
// content:'<h1>Mencoba</h1>'
// })
// marker.addListener('click', function(){
// infoWindow.open(map, marker)
// })
var markers = [
{
position:{ lat: 42.361145, lng: -71.057083 },
icon: 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png',
content: '<h1>Mencoba</h1>'
},
{
position:{ lat: 42.361145, lng: -72.057083 }
}
]
for(let i = 0; i < markers.length; i++) {
addMarker(markers[i])
}
function addMarker({position, icon, content}) {
var marker = new google.maps.Marker({
position,
map
})
if (icon){
marker.setIcon(icon)
}
if(content){
var infoWindow = new google.maps.InfoWindow({
content
})
marker.addListener('click', function(){
infoWindow.open(map, marker);
})
}
}
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyADF12C-4UHJSxqqYsji84CsEq_1c6BbSs&callback=initMap"
async defer></script>
</body>
</html>