0

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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

8 Comments

sure would like to see the documentation for that I must have overlooked it somewhere
oh, and if you want to delay load jsapi itself i would try jquery's getScript
ahh yes that shows you how load the google maps while your page is loading but not after the page is loaded
Mike, I misunderstood your question at first. sorry. i would use jquery to load the loader and then load maps using the loader :)
|
1

This documentation explains how to delay/dynamic load the maps api: http://code.google.com/apis/ajax/documentation/#Dynamic

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.