-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadjust_zoom_level.html
66 lines (60 loc) · 2.11 KB
/
adjust_zoom_level.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
#map {
position: absolute;
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div><a href="https://onethinglab.wordpress.com/the-definitive-guide-to-google-maps-markers#remove-marker">How to adjust zoom level to include all visible markers on screen</a></div>
<div id="map"></div>
<script>
var places = {
'JP': [{ lat: 35.652832, lng: 139.839478 },
{ lat: 35.443707, lng: 139.638031 },
{ lat: 42.923901, lng: 143.196106 },
{ lat: 26.212313, lng: 127.679153 },
{ lat: 26.359266, lng: 127.756744 }],
'US': [{ lat: 42.336983, lng: -83.273262 },
{ lat: 34.704929, lng: -81.210251 },
{ lat: 43.224194, lng: -86.235809 },
{ lat: 34.426388, lng: -117.300880 },
{ lat: 34.686787, lng: -118.154160 }],
'MG': [{ lat: -21.000000, lng: 48.150002 },
{ lat: -16.916668, lng: 47.716667 },
{ lat: -19.002846, lng: 46.460938 },
{ lat: -18.948902, lng: 48.224426 },
{ lat: -13.319158, lng: 48.185768 }]
};
function add_marker(gmap, coordinates, text) {
var marker = new google.maps.Marker({
position: coordinates,
map: gmap,
label: { text: text }
});
return marker;
}
function init_map() {
var gmap = new google.maps.Map(document.getElementById('map'),
{
zoom: 4,
center: { lat: -25.363, lng: 131.044 }
});
var bounds = new google.maps.LatLngBounds();
for (var country in places) {
places[country].forEach(place => {
add_marker(gmap, place, country);
bounds.extend(place);
});
}
gmap.fitBounds(bounds);
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?callback=init_map"></script>
</body>
</html>