前端嵌入高德地图

操作步骤

  1. 首先需要去申请一个key,直接在控制台添加就好了,链接
  2. 页面中合适的位置创建一个div,并有一个id
  3. 使用上面div的id创建一个map对象,导入相应的js链接和key值,链接
  4. 图面显示出地图,链接
  5. 地图上有一些插件可以使用,链接

效果图

在这里插入图片描述

code

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <style type="text/css">
        body,
        html,
        #meMap {
            width: 100%;
            height: 100%;
            margin: 0px
        }
    </style>
    <title>简单地图加载</title>
</head>

<body>
    <div id="meMap" tabindex="0"></div>
    <script src="https://webapi.amap.com/maps?v=1.4.2&key=58a21c1753060ec67806dab865753535"></script>
    <script type="text/javascript" src="https://webapi.amap.com/demos/js/liteToolbar.js"></script>
    <script type="text/javascript">
        var map = new AMap.Map('meMap', {
            resizeEnable: true,
            center: [122, 35.88989],
            zoom: 15,
            viewMode: '3D' //使用3D视图
        });
        AMap.plugin('AMap.ToolBar', function() {
            var toolbar = new AMap.ToolBar();
            map.addControl(toolbar)
        });

        var marker = new AMap.Marker({
            position: map.getCenter(), //标记的位置坐标
            offset: new AMap.Pixel(-5, -5), //标记相对位置的偏移,对应style的left和top
            icon: ico, //创建好的icon,也可以在后面使用setIcon()方法添加
            zoom: 13
        });

        marker.setTitle("当前的位置");
        marker.setLabel({
            offset: new AMap.Pixel(10, 30),
            content: "当前的位置"
        });

        var ico = new AMap.Icon({
            size: new AMap.Size(24, 30), // 图标尺寸
            image: 'static/333.jpeg', // Icon的图像
            imageOffset: new AMap.Pixel(0, 0), // 图像相对展示区域的偏移量,适于雪碧图等
            imageSize: new AMap.Size(24, 30) // 根据所设置的大小拉伸或压缩图片,对应style的width和height
        });

        map.add(marker); //将创建好的marker放到地图上面
    </script>
</body>
</html>
  • 9
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

githubcurry

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值