jQuery(document).ready(function( $ ) { var map, marker, i; function initialize() { var latlng = new google.maps.LatLng(-36.802962, 144.640503); var myOptions = { zoom: 7, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById("sb-maps"), myOptions); //console.log(locations); infowindow = new google.maps.InfoWindow(); if (locations.length && locations.length > 0) { for (i = 0; i < locations.length; i++) { marker = new google.maps.Marker({ position: new google.maps.LatLng( locations[i][1], locations[i][0] ), map: map, icon: mapIcon, }); google.maps.event.addListener(marker, 'click', (function(marker, i) { return function() { infowindow.setContent(locations[i][2]); infowindow.setOptions({ maxWidth: 300, height: 175 }); infowindow.open(map, marker); } })(marker, i)); } } } google.maps.event.addDomListener(window, "load", initialize); });