Improve centering of map with multiple markers
This commit is contained in:
parent
054cd475aa
commit
a48654ca65
1 changed files with 5 additions and 0 deletions
|
|
@ -106,13 +106,18 @@
|
|||
center: map_center,
|
||||
zoom: 15
|
||||
});
|
||||
var bounds = new google.maps.LatLngBounds();
|
||||
for(var i = 0; i < places.length; i++){
|
||||
var marker = new google.maps.Marker({
|
||||
position: {lat: parseFloat(places[i]['lat']), lng: parseFloat(places[i]['lng']) },
|
||||
map: map
|
||||
});
|
||||
marker.setVisible(true);
|
||||
bounds.extend(marker.getPosition());
|
||||
}
|
||||
this.map.fitBounds(bounds);
|
||||
if(map.getZoom() > 15)
|
||||
map.setZoom(15);
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue