layui引入百度地图

javascript 复制代码
<script type="text/javascript" src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=你的ak"></script>
<script src="https://code.bdstatic.com/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script src="layui/layui.js"></script>
<body>

<div class="layui-fluid">
    <!--地图显示位置-->
    <div class="layui-row">
        <div id="l-map" style="height: 810px;width: 1666px"></div>
    </div>
</div>
<script>
    // 百度地图API功能
    var map = new BMapGL.Map("l-map");
    map.centerAndZoom(new BMapGL.Point(119.506999,39.90779), 13);
    map.enableScrollWheelZoom(true);

    $.ajax({
        url: "/admin/ceshi/map_ceshi",
        type: 'get',
        dataType: 'json',
        success: function (adds) {
            for(var i = 0; i<adds.length; i++){
                var point = new BMapGL.Point(adds[i].lng, adds[i].lat);
                var marker = new BMapGL.Marker(point);
                map.addOverlay(marker);
                marker.setLabel(new BMapGL.Label(adds[i].name,{offset:new BMapGL.Size(10,-10)}));
            }
        },
    });
</script>
</body>
javascript 复制代码
接口/admin/ceshi/map_ceshi
adds读出的数据格式为数组:
[
    {
        "id": 1,
        "name": "35624便利店",
        "lng": "119.63569",
        "lat": "39.945388"
    },
    {
        "id": 2,
        "name": "利群超市",
        "lng": "119.548496",
        "lat": "39.933055"
    }
]

获取AK是需要注册一个百度地图开放平台账号,链接地址:

百度地图开放平台 | 百度地图API SDK | 地图开发 (baidu.com)

相关推荐
爱勇宝5 小时前
大多数人不是在使用 AI 赚钱,而是在帮 AI 公司赚钱
前端·后端·程序员
冬奇Lab6 小时前
每日一个开源项目(第143篇):page-agent - 纯 JS 的网页 GUI Agent,无需截图、无需插件、无需后端
前端·人工智能·agent
IT_陈寒10 小时前
React的这个渲染问题连官方文档都没说清楚
前端·人工智能·后端
追逐时光者11 小时前
别再满网找零散工具了,腾讯 QQ 浏览器这个“帮小忙”工具箱真能省时间
前端·后端
Asmewill13 小时前
grep&curl命令学习笔记
前端
stringwu13 小时前
Flutter 开发必备:MVI 架构的高效实现指南
前端·flutter
用户21366100357214 小时前
Vue2组件化开发与父子通信
前端·vue.js
Momo__15 小时前
TypeScript satisfies 操作符——比 as 更安全的类型守门员
前端·typescript
用户21366100357215 小时前
Vue2事件系统与指令进阶
前端·vue.js
labixiong15 小时前
实现一个能跑的迷你版Promise(一)
前端·javascript·面试