var lat; var long; function initialize_street_view() { var position = new google.maps.LatLng(lat,long); var mapOptions = { position: position, pov: { heading: 34, pitch: 10 } }; var smap = new google.maps.StreetViewPanorama(document.getElementById('street_view_canvas'),mapOptions); smap.setStreetView(smap); } $(document).ready(function() { $('#street-view').click(function() { var pc = 'WR15 8TR'; if (pc != '') { $.getJSON('/site/templates/functions/gg.php?pc='+pc, function(data) { lat = data.results[0].geometry.location.lat; long = data.results[0].geometry.location.lng; $.getScript('https://maps.google.com/maps/api/js?sensor=false&callback=initialize_street_view'); }); } return false; }); });