【H5】使用高德地图API
1.打开高德地图开放平台 https://lbs.amap.com 注册开发者账号
2.获取key,上线项目获取地图需要自己的key验证身份
获取结果如下:
通过获取的key绘制获取地图
地图演示链接: https://lbs.amap.com/api/javascript-api/example/map-lifecycle/map-show
演示代码如下:
<!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">
<!-- 引用地图需要的css样式 -->
<link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
<title>地图显示</title>
<style>
html,body,#container {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<!-- 在container内显示地图 -->
<div id="container"></div>
<!-- 加载地图JSAPI脚本 切记:key后面写你自己的key值 -->
<script src="https://webapi.amap.com/maps?v=1.4.14&key=4c7926ce25615845bde087b450e1f4e9"></script>
<script>
var map = new AMap.Map('container', {
resizeEnable: true, //是否监控地图容器尺寸变化
zoom:11, //初始化地图层级
center: [116.397428, 39.90923] //初始化地图中心点的经纬度
});
</script>
</body>
</html>