I have a small button on my page that should load a google map. Since I want my page to load very fast, and this function is not really needed, I don’t want to embed the google maps script API in the page load. I just want to download it when the button is pressed.
I tried using the jquery $ .getScript () method, however, if I use the code above, I get a blank page. The page starts loading, and as soon as my javascript file is executed, the page is blank (white).
$.getScript("http://maps.google.com/maps/api/js?sensor=false", function(){
$('#googleMap').live('click', function(e) {
e.preventDefault();
loadMap("mapBottomContainer", false);
});
});
What am I doing wrong here?
edit / update:
It doesn't seem to matter if I do this:
$('#googleMap').live('click', function(e) {
$.getScript("http://maps.google.com/maps/api/js?sensor=false", function(){
e.preventDefault();
loadMap("mapBottomContainer", false);
});
});
The page is not blank on the page, however, as soon as I press the map button, the page bleaches.
update 2:
loadMap function:
function loadMap(cont, scroll) {
var latlng = new google.maps.LatLng(47.244236,11.249194);
var options = {
zoom: 14,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
scrollwheel: scroll,
streetViewControl: false,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL
}
}
var map = new google.maps.Map(document.getElementById(cont), options);
var mapdesc = '<div id="gmContent">'+
'<h3 id="gmTitle" class="widget-title">Something</h3>'+
'<div id="gmBody">'+
'</div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: mapdesc
});
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: 'My Title'
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
infowindow.open(map,marker);
}