4

I am using bing map in my application for searching. Bing map V8 control.

I have used this CDN

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

after that when I am trying to use Microsoft.Maps. It is saying:

Uncaught ReferenceError: Microsoft is not defined

new Microsoft.Maps.Color(100,100,0,100); 

Any one have idea about this?

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
yaswant singh
  • 349
  • 2
  • 17

2 Answers2

5

Don't use async while loading Bing API,

<script src='http://www.bing.com/api/maps/mapcontrol?callback=GetMap&key=api_key'
          type='text/javascript' ></script>

And if you are using jQuery then add $.ready() to use maps like

<script>
   $(function(){
       var color = new Microsoft.Maps.Color(100,100,0,100); 
       ....
   });    
</script>
Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106
2

I encountered a similar error while using bing maps js sdk. All you have to do is to add 'windows.' before you write: Microsoft.Maps.Color(100,100,0,100);

So now the new code is :

new window.Microsoft.Maps.Color(100,100,0,100);