代码结构
搭建小型web服务器
npm init -y
npm install --save-dev express
const express
= require("express");
const server
= express();
server
.use(express
.static("src"));
server
.listen(3000,function(){
console
.log("listening on *:3000");
})
node server.js启动该服务。
前端代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="https://webapi.amap.com/maps?v=2.0&key=*************"></script>
<style>
#container{
width: 500px;
height: 300px;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var map = new AMap.Map('container', {
center: [116.397428, 39.90923],
zoom: 13
});
</script>
</body>
</html>
https://webapi.amap.com/maps?v=2.0&key=*************,其中key值需要在高德开放平台上申请获取。
效果
参考文档
高德地图开发文档
转载请注明原文地址: https://lol.8miu.com/read-24342.html