none
Passing in the key other than URL/Map module RRS feed

  • Question

  • The problem I am having is that I only want the auto suggest with out the map but  there seems to be no way to pass in the key other than loading the map module (I don't need the map) or passing it in as a hard coded parameter of the URL (I don't want to hard code this, different key for different environment/I don't want to expose this key).

    Is there away to pass in the key to the auto suggest module without passing it as a parameter in the url when we are loading the map control?

    Thursday, March 8, 2018 7:18 PM

Answers

  • There are two ways you can add your key without loading a map. The first, you already mentioned, is to add your key to the map script URL:

    <script type='text/javascript' src='https://www.bing.com/api/maps/mapcontrol?branch=experimental&key=YourBingMapsKey' async defer></script>

    The second, is you can pass it in as an option when loading the module:

    Microsoft.Maps.loadModule('Microsoft.Maps.Autosuggest', {
    	credentials: 'YOUR_BING_MAPS_KEY',
    	callback: function(){
    	//Module loaded, add code.
    
    }});

    This is documented here: 

    https://msdn.microsoft.com/en-us/library/mt712649.aspx

    https://msdn.microsoft.com/en-us/library/mt712651.aspx

    There are no code samples showing this as passing the Bing Maps key into the map script URL is the recommend way to authenticate your usage as this would allow the Bing Maps Enterprise support team to resolve production issues related to release updates much faster as they can roll back your individual app if the issue was limited to your app or a small number of apps.


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Friday, March 9, 2018 2:52 PM
    • Marked as answer by Jack Thor Friday, March 9, 2018 6:28 PM
    Friday, March 9, 2018 2:52 PM

All replies

  • There are two ways you can add your key without loading a map. The first, you already mentioned, is to add your key to the map script URL:

    <script type='text/javascript' src='https://www.bing.com/api/maps/mapcontrol?branch=experimental&key=YourBingMapsKey' async defer></script>

    The second, is you can pass it in as an option when loading the module:

    Microsoft.Maps.loadModule('Microsoft.Maps.Autosuggest', {
    	credentials: 'YOUR_BING_MAPS_KEY',
    	callback: function(){
    	//Module loaded, add code.
    
    }});

    This is documented here: 

    https://msdn.microsoft.com/en-us/library/mt712649.aspx

    https://msdn.microsoft.com/en-us/library/mt712651.aspx

    There are no code samples showing this as passing the Bing Maps key into the map script URL is the recommend way to authenticate your usage as this would allow the Bing Maps Enterprise support team to resolve production issues related to release updates much faster as they can roll back your individual app if the issue was limited to your app or a small number of apps.


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Friday, March 9, 2018 2:52 PM
    • Marked as answer by Jack Thor Friday, March 9, 2018 6:28 PM
    Friday, March 9, 2018 2:52 PM
  • I know that the map module is different, but I was reading up on it and notice that the credentials option is deprecated for the Map module, so I though it was for all modules.

    https://msdn.microsoft.com/en-us/library/mt712646.aspx


    • Edited by Jack Thor Friday, March 9, 2018 5:34 PM
    Friday, March 9, 2018 5:33 PM
  • Even though this is deprecated, it still works. The preference is that the key is always specified in the map script URL, but if you don't want to do that, the specifying it when loading the module will work as well.

    [Blog] [twitter] [LinkedIn]

    Friday, March 9, 2018 6:26 PM
  • Yeah, exposing a PROD key like that is not good design and would not pass code review at my company. I might be able to get away with passing it in the module.
    • Edited by Jack Thor Friday, March 9, 2018 6:30 PM
    Friday, March 9, 2018 6:29 PM
  • Thanks.
    Friday, March 9, 2018 6:34 PM