-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathput-multiple-marker.html
71 lines (63 loc) · 1.44 KB
/
put-multiple-marker.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
<!DOCTYPE html>
<html>
<head>
<title>Put markers</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<div>
<button onclick="reset()">Reset</button>
<button onclick="save()">Save</button>
</div>
<script>
var latLngs = [];
var markers = [];
var map;
function reset() {
// clearing markers
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(null);
}
latLngs = [];
}
function save(){
for (var i = 0; i < latLngs.length; i++) {
console.log(latLngs[i].lat() + ' - ' + latLngs[i].lng());
}
}
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 5,
center: {lat: 46.2276, lng: 2.2137 }
});
map.addListener('click', function(e) {
placeMarkerAndPanTo(e.latLng, map);
});
}
function placeMarkerAndPanTo(latLng, map) {
var marker = new google.maps.Marker({
position: latLng,
map: map,
icon: 'http://maps.google.com/mapfiles/ms/icons/red-dot.png'
});
markers.push(marker);
latLngs.push(latLng);
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_OWN_KEY&signed_in=true&callback=initMap"
async defer>
</script>
</body>
</html>