简体   繁体   English

错误:使用 Mapbox GL 需要一个 API 访问令牌

[英]Error: An API access token is required to use Mapbox GL

I am using react-gl library to use the map-api using mapbox.我正在使用 react-gl 库来使用 map-api 使用 mapbox。 I have created an account mapbox as well still it is showing the error depicted in the picture.我也创建了一个帐户映射框,它仍然显示图片中描述的错误。

Here is my code for app.js这是我的 app.js 代码




import * as React from 'react';
import Map from 'react-map-gl';

function App() {
  return (
    <Map
      initialViewState={{
        longitude: -122.4,
        latitude: 37.8,
        zoom: 14
      }}
      mapboxApiAccessToken = {process.env.REACT_APP_MAPBOX}
      style={{width: 600, height: 400}}
      mapStyle="mapbox://styles/mapbox/streets-v9"
    />
  );
}

export default App

Here is the error:这是错误: 在此处输入图像描述

这是我在 vscode 中的错误

I faced the same problem.我遇到了同样的问题。 You must to change mapboxApiAccessToken to mapboxAccessToken.您必须将 mapboxApiAccessToken 更改为 mapboxAccessToken。

Big shout out to Dani Pérez .Dani Pérez大声喊叫。 Apparently his answer is correct.显然他的回答是正确的。 Just to add on to his answer, in react-map-gl v7.0 , they decided to rename various props and one of those props is mapboxApiAccessToken只是为了补充他的答案,在react-map-gl v7.0中,他们决定重命名各种道具,其中一个道具是mapboxApiAccessToken

Renamed props for better consistency with the wrapped library:重命名道具以更好地与包装库保持一致:

  • mapboxApiAccessToken is now mapboxAccessToken mapboxApiAccessToken现在是mapboxAccessToken

This is mentioned in their Upgrade guide : https://visgl.github.io/react-map-gl/docs/upgrade-guide这在他们的升级指南中提到: https://visgl.github.io/react-map-gl/docs/upgrade-guide

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM