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)

相关推荐
持久的棒棒君7 分钟前
ElementUI 2.x 输入框回车后在调用接口进行远程搜索功能
前端·javascript·elementui
2401_8572979117 分钟前
秋招内推2025-招联金融
java·前端·算法·金融·求职招聘
undefined&&懒洋洋1 小时前
Web和UE5像素流送、通信教程
前端·ue5
大前端爱好者3 小时前
React 19 新特性详解
前端
小程xy3 小时前
react 知识点汇总(非常全面)
前端·javascript·react.js
随云6323 小时前
WebGL编程指南之着色器语言GLSL ES(入门GLSL ES这篇就够了)
前端·webgl
随云6323 小时前
WebGL编程指南之进入三维世界
前端·webgl
寻找09之夏4 小时前
【Vue3实战】:用导航守卫拦截未保存的编辑,提升用户体验
前端·vue.js
多多米10055 小时前
初学Vue(2)
前端·javascript·vue.js
柏箱5 小时前
PHP基本语法总结
开发语言·前端·html·php