Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bing Maps V8 -Uncaught ReferenceError: Microsoft is not defined

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?

like image 787
yaswant singh Avatar asked Sep 17 '25 03:09

yaswant singh


2 Answers

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>
like image 88
Rohan Kumar Avatar answered Sep 19 '25 19:09

Rohan Kumar


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);

like image 39
SHIVANG YADAV Avatar answered Sep 19 '25 18:09

SHIVANG YADAV