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>
相关推荐
不买Huracan不改名5 分钟前
安装Codex(需要用npm)
前端·npm·node.js
Dorcas_FE13 分钟前
axios请求缓存与重复拦截:“相同请求未完成时,不发起新请求”
前端·spring·缓存
dreams_dream21 分钟前
vue中axios与fetch比较
前端·javascript·vue.js
wallflower202040 分钟前
Web Workers:前端多线程解决方案
性能优化·html
梦鱼41 分钟前
Vue 项目图标一把梭:Iconify 自用小记(含 TS/JS 双版本组件)
前端·javascript·vue.js
best66642 分钟前
Flex 与 Grid 的 order 参数:布局界的 "插队神器"
前端
小噔小咚什么东东43 分钟前
看到了很多次WebRTC,但是你真的需要它吗?
前端·webrtc
猫七先生44 分钟前
微信小程序一键登录可行性方案
前端·微信小程序
维他AD钙44 分钟前
前端开发 8 个非常实用小技巧:高效解决日常开发痛点
前端