Dovah520 2021-10-22 20:37 采纳率: 50%
浏览 23

浏览器端调用百度地图API,但地图无显示


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>食堂餐厅地图</title>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">

<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.0&type=webgl&ak=ilfG6CNWbp3rE5SwGqkHhImDmGp7tUO8"></script>

    <style>
/*默认的宽:1440px;默认的高:1024px*/
        #logo {
            width: 18%;
            height: 13%;
            float: left;
        }

        #head {
            width: 82%;
            height: 13%;
            float: left;
            position: relative; left: 18%;
            font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif;
            font-size: x-large;
        }

        #map {
            width: 100%;
            height: 100%;
            position: relative;
            overflow: hidden;
            margin: 0;
            font-family: "微软雅黑";
        }

        #table {
            width: 28%;
            height: 87%;
            position: absolute; left: 0; top: 140px; 
            
        }

        #scene {
            width: 200px;
            height: 100px;
            background-color: brown;
            color: azure;
            text-align: center;
            line-height: 100px;
        } 

        #food {
            width: 200px;
            height: 100px;
            background-color: brown;
            color: azure;
            text-align: center;
            line-height: 100px;
        }

        #post {
            width: 200px;
            height: 100px;
            background-color: brown;
            color: azure;
            text-align: center;
            line-height: 100px;
        }

        #sport {
            width: 200px;
            height: 100px;
            background-color: brown;
            color: azure;
            text-align: center;
            line-height: 100px;
        }

        #traffic {
            width: 200px;
            height: 100px;
            background-color: brown;
            color: azure;
            text-align: center;
            line-height: 100px;
        }

        #shopping {
            width: 200px;
            height: 100px;
            background-color: brown;
            color: azure;
            text-align: center;
            line-height: 100px;
        }

        ul li {
            list-style: none;
        }

        .btn-wrap {
            z-index: 999;
            position: fixed;
            bottom: 3.5rem;
            margin-left: 3rem;
            padding: 1rem 1rem;
            border-radius: .25rem;
            background-color: #fff;
            box-shadow: 0 2px 6px 0 rgba(27, 142, 236, 0.5);
        }

        .btn {
            width: 75px;
            height: 30px;
            float: left;
            background-color: #fff;
            color: rgba(27, 142, 236, 1);
            font-size: 14px;
            border:1px solid rgba(27, 142, 236, 1);
            border-radius: 5px;
            margin: 0 5px;
            text-align: center;
            line-height: 30px;
        }

        .btn:hover {
            background-color: rgba(27, 142, 236, 0.8);
            color: #fff;
        }
    </style>
</head>


<body>
    <div id="logo">
        <img src="logo0.png" width="10%" style="position: absolute; left: 3%; top: 0;">
    </div>

    <div id="head">
        <img src="whitelogo.png" width="300px" height="134px" style="position: absolute; left: 350px;">
        <img src="red.jpg" width="1182px" height="134px">
        
    </div>

    <div id="map">
        <img src="lightred.jpg" width="1440px" height="890px">
    </div>

    <div id="table">
        <div id="scene">
            <h2>景点</h2>
        </div>
        <div id="food">
            <h2>饮食</h2>
        </div>
        <div id="post">
            <h2>快递</h2>
        </div>
        <div id="sport">
            <h2>运动</h2>
        </div>
        <div id="traffic">
            <h2>交通</h2>
        </div>
        <div id="shopping">
            <h2>购物</h2>
        </div>
    </div>

    <ul class="btn-wrap" style="z-index: 99;">
        <li class = "btn" onclick = "addRouteType()">叠加路况</li>
        <li class = "btn" onclick = "removeRouteType()">删除路况</li>
        </ul>

        <script>
            var map = new BMapGL.Map("map"); // 创建地图实例
            var point = new BMapGL.Point(116.404, 39.915); // 创建点坐标
            map.centerAndZoom(point, 15); // 初始化地图,设置中心点坐标和地图级别
            map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
            map.setHeading(64.5); //设置地图旋转角度
            map.setTilt(73); //设置地图的倾斜角度
    
            function addRouteType() {
                map.setTrafficOn(); // 叠加路况图层
                }
                function removeRouteType() {
                map.setTrafficOff(); // 关闭路况图层
                }
        </script>

</body>
</html>
  • 写回答

1条回答 默认 最新

  • 你好!机器人 2021-10-27 16:08
    关注

    img


    把height改成一个固定值,比如height:500px;
    或者将相对定位改成绝对定位
    position:absolute

    评论

报告相同问题?

问题事件

  • 创建了问题 10月22日

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器