开发者

load google maps in javascript file

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('&l开发者_JAVA百科t;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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜