title: Load BingMaps API on runtime
body: <p>I am trying to load the Bing Maps API during runtime of my JavaScript file. Here is what i have got so far, based on <a href="https://stackoverflow.com/questions/11803215/how-to-include-multiple-js-files-using-jquery-getscript-method">this</a>.</p>
  
  <pre><code>var bingmap_link = 'https://www.bing.com/api/maps/mapcontrol?callback=loadMapScenario';
  $.when(
    $.getScript(bingmap_link),
    $.Deferred(function( deferred ){
      $( deferred.resolve );
    })
  )
  .done(function() {
    console.log("done");
    load_bing_map();
  });
  </code></pre>
  
  <p>But i will get the following error</p>
  
  <blockquote>
    <p>TypeError: Microsoft.Maps.NetworkCallbacks.f_logCallbackRequest is not
    a function</p>
  </blockquote>
  
  <p>So I tried another attempt:</p>
  
  <pre><code>$('head').append('&lt;script type="text/javascript" src="https://www.bing.com/api/maps/mapcontrol?callback=loadMapScenario" async defer&gt;&lt;/script&gt;');
  
  load_bing_map();
  </code></pre>
  
  <p>But I am again running in errors:</p>
  
  <blockquote>
    <p>jQuery.Deferred exception: n is null
    k@<a href="https://www.bing.com/api/maps/mapcontrol?callback=loadMapScenario:12:7416" rel="nofollow noreferrer">https://www.bing.com/api/maps/mapcontrol?callback=loadMapScenario:12:7416</a></p>
  </blockquote>
  
  <p>In both cases the <code>load_bing_map()</code> function looks like this.</p>
  
  <pre><code>function load_bing_map() {
    var map = new Microsoft.Maps.Map('#mymap', {
      credentials: 'MyKey'
    });
  }
  </code></pre>
  
  <p>The code is executed after the <code>$().ready</code> trigger is fired.</p>
  
  <p>What am I missing?</p>
  
  <p>Finally I do not need a solution like</p>
  
  <pre><code>&lt;head&gt;
    &lt;script type='text/javascript' src='https://www.bing.com/api/maps/mapcontrol?callback=loadMapScenario' async defer&gt;&lt;/script&gt;
  &lt;/heady&gt;
  </code></pre>
  
  <p>I can only do it during runtime.</p>