Risolto così:
codice:
var bounds = new google.maps.LatLngBounds();
var infowindow = new google.maps.InfoWindow();
function initializeMap() {
var mapOptions = {
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map-container'), mapOptions);
getMapData();
}
function getMapData() {
var jsonStrutture = $.parseJSON(JSON.stringify(objStrutture));
if (jsonStrutture.length > 0) {
$.each(jsonStrutture, function () {
addMarker(this);
});
//now fit the map to the newly inclusive bounds
map.fitBounds(bounds);
}
}
function addMarker(objStruttura) {
...
if (lat != null && lng != null) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lng),
map: map
});
//extend the bounds to include each marker's position
bounds.extend(marker.position);
if (img != '') {
image = '<img src="' + img + '" width="200" />';
}
var content = '<div class="col-sm-12 row box-mappa">' +
'<h5><span class="titolo-mappa">' + struttura + '</span> ' + stelle + '</h5>' +
image +
'<h6>' + indirizzo + '</h6>' +
'<div class="text-left box-prezzo">' +
notti + ' ' + lgNotti + ' ' +
(totale < scontato ? '<span class="scontato-mappa">€ ' + scontato + '</span> ' : '') +
'<span class="prezzo-mappa">€ ' + totale + '</span>' +
'</div>' +
'<div class="pull-right margin-top10">' +
'<a id="hlPrenota" class="prenotaEvent button-mappa pointer" data-code="' + codiceStruttura + '">' + lgPrenota + '</a>' +
'</div>' +
'</div>';
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infowindow.setContent(content);
infowindow.open(map, marker);
}
})(marker, i));
}//end if
}