html接入高德地图

1.申请key

key申请地址:https://console.amap.com/dev/key/app

官方文档

https://lbs.amap.com/api/javascript-api-v2/summary

2.html接入示例

  • 需要将YOUR_KEY替换成自己的key
html 复制代码
<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  <title>高德地图demo</title>
  <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
  <style>
    html,
    body,
    #container {
      height: 100%;
      width: 100%;
    }

    .amap-icon img,
    .amap-marker-content img {
      width: 25px;
      height: 34px;
    }

    .cus_info_window {
      background-color: #fff;
      padding: 10px;
    }
  </style>
</head>

<body>
  <div id="container"></div>
  <script type="text/javascript" src="https://webapi.amap.com/maps?v=2.0&key=YOUR_KEY"></script>
  <script type="text/javascript">
    // 创建地图实例
    var map = new AMap.Map("container", {
      zoom: 18,
      center: [104.70049, 29.422945],
      resizeEnable: true
    });

    // 创建点覆盖物
    var marker = new AMap.Marker({
      position: new AMap.LngLat(104.70049, 29.422945),
      icon: 'https://a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png',
      offset: new AMap.Pixel(-13, -30)
    });
    map.add(marker);
	
	// 创建信息窗体
    var infoWindow = new AMap.InfoWindow({
      isCustom: true,  // 使用自定义窗体
      content: '<div class="cus_info_window">世界无花果博览园</div>', // 信息窗体的内容可以是任意 html 片段
      offset: new AMap.Pixel(16, -45)
    });
    var onMarkerClick = function (e) {
      infoWindow.open(map, e.target.getPosition()); // 打开信息窗体
      // e.target 就是被点击的 Marker
    }

    marker.on('click', onMarkerClick); // 绑定 click 事件
  </script>
</body>

</html>
相关推荐
IMPYLH3 小时前
HTML 的 <abbr> 元素
前端·算法·html
李白的天不白4 小时前
Tree-Shaking
前端
Csvn4 小时前
TypeScript:你以为安全的 `JSON.parse` 其实是颗雷 — 运行时类型安全实战
前端·javascript
橘子星4 小时前
深入理解线性数据结构:栈、队列与链表
前端·javascript
dadaobusi4 小时前
Linux内核完成大量内存/调度/时间子系统初始化的关键阶段
java·linux·前端
用户059540174464 小时前
Redis 缓存过期不一致踩坑实录:一个 bug 让我排查了 3 小时,最终用 Pytest 自动化堵上漏洞
前端·css
东风破_4 小时前
AJAX 异步请求:从回调地狱到 async/await,到底解决了什么?
前端
Larcher4 小时前
JS 数据类型的八重人格与内存真相
前端·javascript
星辰徐哥4 小时前
工具推荐:HTML5+AI开发必备的前端调试工具
前端·人工智能·html5
Full Stack Developme4 小时前
Linux Shell 教程概览
linux·前端·chrome