gpt4 book ai didi

javascript - BingMap - 获取空错误的原型(prototype)

转载 作者:行者123 更新时间:2023-11-30 15:24:49 24 4
gpt4 key购买 nike

我搜索了 google 和 stackoverflow,但找不到针对此问题的解决方案。我在我的 view 中像这样加载 map

<img
ng-src='https://dev.virtualearth.net/REST/v1/Imagery/Map/Road/
{{Latitude.__text}},{{Longitude.__text}}/12?mapSize=77,120&amp;
key={{Key}}'></img>

下面是它在 index.html 中的加载方式

<script type='text/javascript' src='https://www.bing.com/mapspreview/sdkrelease/mapcontrol?callback=loadMapScenario' async defer></script>
<script type='text/javascript' src='app/services/bing.js?' async defer></script>

下面是我的 Controller 代码,我试图在其中调用 map

function GetMap() {
if (typeof Microsoft !== undefined && typeof Microsoft.Maps !== undefined &&
Microsoft.Maps.Map !== null) {
//Map API available add your map load code.
angular.element(document).ready(function() {
map = new Microsoft.Maps.Map(document.getElementById('myMapL'), {
credentials: Key,
mapTypeId: "r",
zoom: 4
});
});
} else {
setTimeout(GetMap(), 100);
}
}

我收到以下错误:

TypeError: Cannot read property 'prototype' of null
at k (bing.js:11)
at h (bing.js:11)
at e (bing.js:11)
at t.l [as instance] (bing.js:11)
at h (bing.js:11)
at e (bing.js:11)
at t.l [as instance] (bing.js:11)
at new Microsoft.Maps.Map (bing.js:13)
at HTMLDocument.<anonymous> (file-location.js:121)
at j (jquery-1.11.0.min.js:2)

最佳答案

在 map 脚本 URL 中,您使用不同的回调函数来加载 map 。 (loadScenario 与 GetMap)。此外,看起来您使用的是重定向 URL 而不是记录的 map 脚本 URL(将来可能会中断)。尝试将 map 脚本 URL 更改为:

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

不确定您的应用程序中有什么 bing.js。假设这是您映射加载代码的地方。您需要在 map 脚本之前加载它,否则 map 脚本可能会在您的代码之前加载,因此会尝试在您的 GetMap 函数加载到页面之前加载 map 。

或者,您可能会发现此代码示例很有用:https://github.com/Microsoft/BingMapsV8CodeSamples/blob/master/Samples/Experimental/Map_WithAngular1.html

关于javascript - BingMap - 获取空错误的原型(prototype),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43162044/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com