引入百度地图api不显示地图

来源:8-1 (上)销售大盘地图组件开发

慕神4213171

2024-08-16

在index.html中引入api:
<script type="text/javascript" async src="https://api.map.baidu.com/api?v=2.0&ak=1XjLLEhZhQNUzd93EjU5nOGQ"></script>
项目运行后,终端没报错,但是网页上不显示地图,控制台报警告:

Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.
(anonymous) @ api?v=2.0&ak=1XjLLEhZhQNUzd93EjU5nOGQ:1
(anonymous) @ api?v=2.0&ak=1XjLLEhZhQNUzd93EjU5nOGQ:1

点开api?v=2.0&ak=1XjLLEhZhQNUzd93EjU5nOGQ,里面的代码如下:

(function() {
    window.HOST_TYPE = "2";
    window.BMap_loadScriptTime = (new Date).getTime();
    document.write('<script type="text/javascript" src="https://api.map.baidu.com/getscript?v=2.0&ak=1XjLLEhZhQNUzd93EjU5nOGQ&services=&t=20240731110958"></script>');
}
)();

写回答

1回答

Sam

2024-08-19

同学你好,尝试把script标签中的async去掉试试:

<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=1XjLLEhZhQNUzd93EjU5nOGQ"></script>

0
2
慕神4213171
api?v=2.0&ak=1XjLLEhZhQNUzd93EjU5nOGQ:1 A parser-blocking, cross site (i.e. different eTLD+1) script, https://api.map.baidu.com/getscriptv=2.0&ak=1XjLLEhZhQNUzd93EjU5nOGQ&services=&t=20240731110958, is invoked via document.write. The network request for this script MAY be blocked by the browser in this or a future page load due to poor network connectivity. If blocked in this page load, it will be confirmed in a subsequent console message. See https://www.chromestatus.com/feature/5718547946799104 for more details. 57 Third-party cookie will be blocked. Learn more in the Issues tab. 参考其他问题的回答,给组件加上宽高后,地图还是不显示, 并且报错:GET http://172.18.67.16:8082/sockjs-node/info?t=1724250429561 net::ERR_CONNECTION_TIMED_OUT
2024-08-21
共2条回复

数据可视化入门到精通-打造前端差异化竞争力

同级别前端,掌握数据可视化薪资更高

1520 学习 · 1043 问题

查看课程