function initialize() { var mapCanvas = document.getElementById('pierlocation'); var mapOptions = { center: new google.maps.LatLng(22.317773, 114.160206), zoom: 15, mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(mapCanvas, mapOptions); var marker = new google.maps.Marker({ position: map.getCenter(), map: map, title: 'Click to zoom' }); google.maps.event.addListener(map, 'center_changed', function() { // 3 seconds after the center of the map has changed, pan back to the // marker. window.setTimeout(function() { map.panTo(marker.getPosition()); }, 3000); }); google.maps.event.addListener(marker, 'click', function() { map.setZoom(18); map.setCenter(marker.getPosition()); infowindow.open(map,marker); }); var info = document.getElementById('piertitle').innerHTML; var infowindow = new google.maps.InfoWindow({ content: info }); infowindow.open(map,marker); } google.maps.event.addDomListener(window, 'load', initialize);