我正在尝试使用传单在网站中构建地图功能,但是以下代码不起作用,当我运行它时,只有缩放图标和版权声明,但地图未显示。 chrome开发人员工具中存在此错误消息“无法加载资源:服务器响应状态为401(未经授权)”。有人可以帮忙吗?非常感谢您的帮助!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.4/dist/leaflet.css"
integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA=="
crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.3.4/dist/leaflet.js"
integrity="sha512-nMMmRyTVoLYqjP9hrbed9S+FzjZHW5gY1TWCHA5ckwXZBadntCNs8kEqAWdrb9O7rxbCaA4lKTIWjDXZxflOcA=="
crossorigin=""></script>
<style>
#mapid {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
</style>
<title>Document</title>
</head>
<body>
<div id="mapid"></div>
</body>
<script>
// initiate leatlet Map
var mymap = L.map("mapid").setView([51.505, -0.09], 13);
L.tileLayer(
"https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}",
{
attribution:
'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 18,
id: "mapbox.streets",
accessToken: "your.mapbox.access.token"
}
).addTo(mymap);
</script>
</html>