![](/img/trans.png)
[英]MapBox stopped working on SquareSpace and Uncaught ReferenceError: mapboxgl is not defined
[英]MapBox: Uncaught ReferenceError: mapboxgl is not defined
我在我的一個網絡應用程序中使用 MapBox,我的目標是在頁面上呈現基本地圖。
我有以下腳本:
<script>
mapboxgl.accessToken = mapToken;
const map = new mapboxgl.Map({
container: 'map', // container ID
style: 'mapbox://styles/mapbox/streets-v11', // style URL
center: [-74.5, 40], // starting position [lng, lat]
zoom: 9 // starting zoom
});
</script>
並顯示地圖,我使用:
<div id='map' style='width: 400px; height: 300px;'></div>
問題是,當我嘗試加載頁面時,沒有任何反應,並且出現以下錯誤: Uncaught ReferenceError: mapboxgl is not defined
我只是通過包含這個來解決這個問題:
<script src='https://api.mapbox.com/mapbox-gl-js/v2.6.0/mapbox-gl.js'></script>
<link href='https://api.mapbox.com/mapbox-gl-js/v2.6.0/mapbox-gl.css' rel='stylesheet' />
在 HTML 文件的頭部。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.