Reputation: 17640
I want to load google maps dynamically so I only load them when needed but I keep getting the error google is not defined here is my code
$(document).ready(function(){
if($('.geotags').length > 0){
$("head").append('<script type="text/javascript" src="http://www.google.com/jsapi?key=keytogooglemapsapi"></script>');
google.load("maps", "2.x", {"other_params":"sensor=false",'callback':build_gmaps});
}
}
EDIT add more code to show where I would like to do this
Upvotes: 0
Views: 2992
Reputation: 2417
This documentation explains how to delay/dynamic load the maps api: http://code.google.com/apis/ajax/documentation/#Dynamic
Upvotes: 1
Reputation: 29538
google has its own loader in their jsapi script that you can use to load maps api. and if you want to delay-load jsapi itself i would try jquery's getScript.
Upvotes: 1