0

I have been trying to fix this since yesterday but I can't get my head around it. I am loading my google map asynchronously but The following code brings up an error which is due to the infobox not being loaded correctly.

My error is: InfoBox is not defined

My code is:

function loadScript(callback) {
   var map = document.createElement('script');
   map.type = 'text/javascript';
   map.src = 'https://maps.googleapis.com/maps/api/js?key=my_key_goes_here&sensor=false&callback=initialize';
   document.body.appendChild(map);            
   map.onload = function() {
      var box = document.createElement('script');
      box.type = 'text/javascript';
      box.src = 'https://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox_packed.js';
      document.body.appendChild(box);
      box.onload = callback;
   };
}           
window.onload = loadScript;
green_arrow
  • 1,257
  • 7
  • 21
  • 37

1 Answers1

0

You specify an argument to your loadScript, 'callback'. Then in your map.src you specify callback=initialize. You call loadScript on window.onload, but you don't specify an argument to it. So box.onload doesn't know any value for callback I'm guessing, as it can't magically guess 'initialize' from the map.src string.

Make sense?

duncan
  • 31,401
  • 13
  • 78
  • 99
  • Yes, I completely understand. I got my answer off here http://stackoverflow.com/questions/12148279/load-js-scripts-asynchronously-in-order-waiting-the-previous-one-is-complete but I see the problem but I can't fix it :( – green_arrow Apr 25 '13 at 15:02
  • In fact do you want the initialize function to be executed on map load or box load? – duncan Apr 25 '13 at 15:33
  • It will need to be execute on box load for it to work, I think – green_arrow Apr 25 '13 at 15:39