function loadData() { $.ajax({type: "POST", url: "http://www.ilkleygrammarschool.com/js/map-ajax.php", data: { load: 'true' } }).done(function( res ) { r = jQuery.parseJSON( res ); load( r ); }); } // Initialisation function function load( googlemap ) { // Look for each map for ( var divID in googlemap ) { if( document.getElementById( divID ) ) { var g = googlemap[ divID ]; var latlng = new google.maps.LatLng(g.lat,g.lng); var options = { zoom: 13, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById( divID ), options); var marker = new google.maps.Marker({ position: new google.maps.LatLng(g.lat, g.lng), map: map }); var infowindow = new google.maps.InfoWindow({ content: '' }); bindInfoWindow(marker, map, infowindow, g.info); } } } function bindInfoWindow(marker, map, infowindow, html) { google.maps.event.addListener(marker, 'click', function() { infowindow.setContent(html); infowindow.open(map, marker); }); } /* google.maps.event.addDomListener(window, 'load', initialize); */ $(document).ready(function() { loadData(); } );