Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bing Maps v8.0 Microsoft.Maps.Location is not a constructor in chrome

Tags:

I am working on Bing Maps Version 8.0 upgrade from Version 6.3. Here is my upgraded code below which is throwing an error:

var Points = [new Microsoft.Maps.Location(0, 0), new Microsoft.Maps.Location(0, 0)]

The above lines after it executes gives me an error saying

"TypeError: Microsoft.Maps.Location is not a constructor"

The above problem happens in Google Chrome browser. But the same works fine in Internet Explorer.

Any suggestion is helpful.

Thanks in advance.

Regards, Rahul

like image 541
Shyam Avatar asked May 30 '17 10:05

Shyam


People also ask

How do I fix Bing Maps?

Data or Bing Maps Website Related Issue To report a data related issue, please go to www.bing.com/maps. In the lower right hand corner, click on the Feedback button as shown below and select General Feedback or Problem on Map.

Is Bing maps the same as Google Maps?

Bing Maps doesn't have any lead over Google Maps in any country. When you compare the mobile experience while using the two Maps, Google Maps is always the winner. While Bing does provide decent images of streets, it cannot compete with Google's widespread image coverage.

Does Microsoft have a Google Maps equivalent?

Bing Maps has had a “My Places” feature, which is very similar to Google's “My Maps” feature, since it first came online in 2005. The “My Places” feature makes it easy to import data from common spatial file formats such as KML, GeoRSS, and GPX.


1 Answers

The issue is likely that you are trying to use the Microsoft.Maps namespace before the map control script is loaded. The V8 map script loads asynchronously for performance, however this means that if you try to access namespace in code right after the script tag to load the map control, the namespace won't be there. You need your code to wait until the map script is loaded. You can handle this by adding a callback function name to the map script tag URL. For example:

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
    <script type='text/javascript'>
    var map;

    function GetMap()
    {
        map = new Microsoft.Maps.Map('#myMap', {
            credentials: 'YourBingMapsKey'
        });

        //Add your post map load code here.
    }
    </script>

    <script type='text/javascript' src='https://www.bing.com/api/maps/mapcontrol?callback=GetMap' async defer></script>
</head>
<body>
    <div id="myMap" style=";width:800px;height:600px;"></div>
</body>
</html>

We also recommend adding the map script tag after your map load code. The reason for this is that if the page is refreshed, the map script will be cached and will call the callback function right away, so the callback function needs to already be loaded.

like image 59
rbrundritt Avatar answered Sep 22 '22 10:09

rbrundritt