高德地图插件的使用

<!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>Document</title>
    <script type="text/javascript"
        src="https://webapi.amap.com/maps?v=2.0&key=346e4aa4dc6444f5a7f69bf1ff66ca1a"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
 
        #container {
            width: 100%;
            height: 100vh;
        }
    </style>
</head>
 
<body>
    <div id="container">
 
    </div>
</body>
<script>
    var map = new AMap.Map('container', {
        zoom: 16,//级别
        center: [113.978255, 35.281454],//中心点坐标
        viewMode: '3D'//使用3D视图
    });
    let data = [
        {
            name: "十点半",
            tel: 123456789,
            posi: [113.98, 35.28]
        }, {
            name: "阿迪斯",
            tel: 45678909876,
            posi: [113.92, 35.29]
        }, {
            name: "盎司九百",
            tel: 0987656789876,
            posi: [113.93, 35.28]
        }
    ]
    for (let i = 0; i < data.length; i++) {
        // 以 icon URL 的形式创建一个途经点
        var viaMarker = new AMap.Marker({
            position: new AMap.LngLat(data[i].posi[0], data[i].posi[1]),
            // 将一张图片的地址设置为 icon
            icon: './img/位置.png',
 
            // 设置了 icon 以后,设置 icon 的偏移量,以 icon 的 [center bottom] 为原点
            offset: new AMap.Pixel(-13, -30)
        });
        viaMarker.on('click', function () {
            infoWindow = new AMap.InfoWindow({
                content: `
            <div class="qwe">
                <h3>${data[i].name}</h3>
                <p>tel:${data[i].tel}</p>
                </div>
            `,
                offset: new AMap.Pixel(4, 0)
            });
            infoWindow.open(map, data[i].posi);
        })// 将 markers 添加到地图
        map.add(viaMarker);
    }
 
 
</script>
 
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值