google-chrome - Bing Maps v8.0 Microsoft.Maps.Location 不是 chrome 中的构造函数

标签 google-chrome bing bing-api bing-maps

我正在从 6.3 版升级 Bing map 8.0 版。下面是我升级后的代码,它抛出了一个错误:

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

执行后的上述几行给了我一个错误说

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



上述问题发生在 Google Chrome 浏览器中。但是在 Internet Explorer 中同样可以正常工作。

任何建议都是有帮助的。

提前致谢。

问候,
拉胡尔

最佳答案

问题很可能是您在加载 map 控制脚本之前尝试使用 Microsoft.Maps 命名空间。 V8 map 脚本以异步方式加载以提高性能,但这意味着如果您尝试在脚本标记之后立即访问代码中的命名空间以加载 map 控件,则命名空间将不存在。您需要您的代码等待 map 脚本加载完毕。您可以通过向 map 脚本标记 URL 添加回调函数名称来处理此问题。例如:

<!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>

我们还建议在 map 加载代码之后添加 map 脚本标签。这样做的原因是,如果刷新页面, map 脚本将被缓存并立即调用回调函数,因此回调函数需要已经加载。

关于google-chrome - Bing Maps v8.0 Microsoft.Maps.Location 不是 chrome 中的构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44260168/

相关文章:

python - 使用 Python 下载 URL 中未明确引用的文档

javascript - 负下边距在 IE 中不起作用

javascript - FB.login() 在 Android Chrome 上失败并显示 "Unsafe JavaScript attempt to initiate navigation for frame"但不是桌面 Chrome

azure - 在 LUIS.ai 中使用 Bing SpellChecker

javascript - 必应 map v8 JS API

android - 如何使用 Bing 翻译服务在 android 上播放特定单词的音频?

bing-maps - Bing Maps Ajax API https url?

javascript - 是否可以将 javascript 插入到 Google Chrome 的 "Inspect Element"中?

html - 删除 Chrome 和 Safari 浏览器中 html5 视频顶部和底部的黑条

azure - Bing 图像搜索 API(认知)返回损坏的链接?