none
Maps.Location undefined While Loading script dynamically RRS feed

  • Question

  • Hi, I'm trying to create script tag and load the script dynamically. Using this URL: http://www.bing.com/api/maps/mapcontrol.

    I am creating onload event of script tag and trying to load the map after that. But I 'm getting error while accessing Microsoft.Maps.Location and other functions after script has been loaded.

     Please assist.



    Jegan

    Wednesday, April 13, 2016 5:29 AM

Answers

  • The Bing Maps control loads a bunch of scripts dynamically on its own. What is likely happening is that you are trying to access it before it has loaded the required scripts. To handle this you can use the callback URL parameter for the map script. For example, if you have some function that dynamically loads scripts called loadScriptDynamically, the following code would work:

    loadScriptDynamically('http://www.bing.com/api/maps/mapcontrol?callback=mapScriptLoaded');
    
    function mapScriptLoaded(){
    	//Script is loaded, start using Microsoft.Maps namespace.
    }

    Alternatively, if you want to include a script reference in your page, you can also use async defer like this:

    <script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?callback=mapScriptLoaded' async defer></script>

    This is documented here: https://msdn.microsoft.com/en-us/library/mt712557.aspx


    [Blog] [twitter] [LinkedIn]

    Wednesday, April 13, 2016 2:56 PM