代码结构
搭建小型web服务器
npm init -y
npm install --save-dev express
// server.js
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>
<!-- index.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
值需要在高德开放平台上申请获取。