$('#collapseMap').on('shown.bs.collapse', function(e){ (function(A) { if (!Array.prototype.forEach) A.forEach = A.forEach || function(action, that) { for (var i = 0, l = this.length; i < l; i++) if (i in this) action.call(that, this[i], i, this); }; })(Array.prototype); var mapObject, markers = [], markersData = { 'Walking': [ { name: 'Villa Gemma', location_latitude: 36.790667, location_longitude: 14.492757, map_image_url: 'js/temp/thumb_mappa_suntripsicily_location_Villa Gemma.jpg', name_point: 'Villa Gemma', description_point: '', get_directions_start_address: '', phone: '+393927661318', url_point: '26-location-villa-gemma.php' }, { name: 'Villa Stella Marina', location_latitude: 36.790707, location_longitude: 14.554283, map_image_url: 'js/temp/thumb_mappa_suntripsicily_location_Villa Stella Marina.jpg', name_point: 'Villa Stella Marina', description_point: '', get_directions_start_address: '', phone: '+393927661318', url_point: '25-location-villa-stella-marina.php' }, { name: 'Villa Ninetta', location_latitude: 36.727468, location_longitude: 14.925557, map_image_url: 'js/temp/thumb_mappa_suntripsicily_location_Villa Ninetta.jpg', name_point: 'Villa Ninetta', description_point: '', get_directions_start_address: '', phone: '+393927661318', url_point: '28-location-villa-ninetta.php' }, { name: 'Villa Pietra Bianca', location_latitude: 36.735191, location_longitude: 14.875918, map_image_url: 'js/temp/thumb_mappa_suntripsicily_location_Villa Pietra Bianca.jpg', name_point: 'Villa Pietra Bianca', description_point: '', get_directions_start_address: '', phone: '+393927661318', url_point: '24-location-villa-pietra-bianca.php' }, ], 'experience': [ { name: 'Skydiving over Syracuse', location_latitude: , location_longitude: , map_image_url: 'js/temp/thumb_mappa_suntripsicily_experience_17.jpg', name_point: 'Skydiving over Syracuse', description_point: '', get_directions_start_address: '', phone: '+393927661318', url_point: '17-experience-skydiving-over-syracuse.php' } ] }; var coords = "36.790667,14.492757|36.790707,14.554283|36.727468,14.925557|36.735191,14.875918|"; var filteredtextCoordinatesArray = coords.split('|'); centerLatArray = []; centerLngArray = []; for (i=0 ; i < filteredtextCoordinatesArray.length ; i++) { var centerCoords = filteredtextCoordinatesArray[i]; var centerCoordsArray = centerCoords.split(','); if (isNaN(Number(centerCoordsArray[0]))) { } else { centerLatArray.push(Number(centerCoordsArray[0])); } if (isNaN(Number(centerCoordsArray[1]))) { } else { centerLngArray.push(Number(centerCoordsArray[1])); } } var centerLatSum = centerLatArray.reduce(function(a, b) { return a + b; }); var centerLngSum = centerLngArray.reduce(function(a, b) { return a + b; }); var centerLat = centerLatSum / filteredtextCoordinatesArray.length ; var centerLng = centerLngSum / filteredtextCoordinatesArray.length ; console.log(centerLat); console.log(centerLng); var mapOptions = { zoom: 8, /*center: new google.maps.LatLng(36.735191, 14.875918),*/ center: new google.maps.LatLng(37.574841, 14.255670), mapTypeId: google.maps.MapTypeId.ROADMAP, mapTypeControl: false, mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU, position: google.maps.ControlPosition.LEFT_CENTER }, panControl: false, panControlOptions: { position: google.maps.ControlPosition.TOP_RIGHT }, zoomControl: true, zoomControlOptions: { style: google.maps.ZoomControlStyle.LARGE, position: google.maps.ControlPosition.TOP_LEFT }, scrollwheel: false, scaleControl: false, scaleControlOptions: { position: google.maps.ControlPosition.TOP_LEFT }, streetViewControl: true, streetViewControlOptions: { position: google.maps.ControlPosition.LEFT_TOP }, styles: [ { "featureType": "landscape", "stylers": [ { "hue": "#FFBB00" }, { "saturation": 43.400000000000006 }, { "lightness": 37.599999999999994 }, { "gamma": 1 } ] }, { "featureType": "road.highway", "stylers": [ { "hue": "#FFC200" }, { "saturation": -61.8 }, { "lightness": 45.599999999999994 }, { "gamma": 1 } ] }, { "featureType": "road.arterial", "stylers": [ { "hue": "#FF0300" }, { "saturation": -100 }, { "lightness": 51.19999999999999 }, { "gamma": 1 } ] }, { "featureType": "road.local", "stylers": [ { "hue": "#FF0300" }, { "saturation": -100 }, { "lightness": 52 }, { "gamma": 1 } ] }, { "featureType": "water", "stylers": [ { "hue": "#0078FF" }, { "saturation": -13.200000000000003 }, { "lightness": 2.4000000000000057 }, { "gamma": 1 } ] }, { "featureType": "poi", "stylers": [ { "hue": "#00FF6A" }, { "saturation": -1.0989010989011234 }, { "lightness": 11.200000000000017 }, { "gamma": 1 } ] } ] }; var marker; mapObject = new google.maps.Map(document.getElementById('map'), mapOptions); for (var key in markersData) markersData[key].forEach(function (item) { marker = new google.maps.Marker({ position: new google.maps.LatLng(item.location_latitude, item.location_longitude), map: mapObject, icon: 'img/pins/' + key + '.png', }); if ('undefined' === typeof markers[key]) markers[key] = []; markers[key].push(marker); google.maps.event.addListener(marker, 'click', (function () { closeInfoBox(); getInfoBox(item).open(mapObject, this); mapObject.setCenter(new google.maps.LatLng(item.location_latitude, item.location_longitude)); })); }); function hideAllMarkers () { for (var key in markers) markers[key].forEach(function (marker) { marker.setMap(null); }); }; function closeInfoBox() { $('div.infoBox').remove(); }; function getInfoBox(item) { return new InfoBox({ content: '