reactjs - React Native undefined 不是对象(评估 'Mapbox.GL.UserTrackingModes' )

标签 reactjs react-native mapbox mapbox-gl-js mapbox-gl

我开始使用 mapbox 来响应 native ,但是,我在使用 npm 或 yarn 安装它以及导入到我的项目时遇到了这个问题,我有点确定这是 mapbox api 的问题还是方式我正在尝试实现这是错误的。

使用 native 版本:

  • react-native-cli: 2.0.1
  • native react :0.57.3

native react :0.57.3

map .js

import React from 'react'; 
import { StyleSheet, Text, View, Image, StatusBar, ScrollView, TouchableOpacity } from 'react-native';
import Mapbox from '@mapbox/react-native-mapbox-gl';

Mapbox.setAccessToken('mapbox-api-key');

class MapScreen extends React.Component {

   constructor(props) {
    super(props);
    this.state = {

    };
  }

  render() {
    return (
        <View style={styles.container}>
        <StatusBar
            backgroundColor={'transparent'}
            translucent/>
            <Mapbox.MapView
                styleURL={Mapbox.StyleURL.Street}
                zoomLevel={15}
                centerCoordinate={[11.256, 43.770]}
                style={styles.container}>
            </Mapbox.MapView>
        </View>
    );
  }
}


export default MapScreen;

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#EFF2F5',
  },
  content: {
    flex: 1,
    flexDirection: 'column',
    alignItems: 'center',
    marginLeft: 40,
    marginRight: 40,
    marginBottom: 30,
  },
  navBar: {
    height: 55,
    backgroundColor: '#fff',
    elevation: 3,
    paddingHorizontal: 15,
    flexDirection: 'row',
    alignItems:'center',
    justifyContent: 'space-between'
  },
  rightNav: {
    flexDirection: 'row'
  },
  navItem: {
    marginLeft: 100
  },
});

最佳答案

确保您在 android gradle 文件上正确设置依赖项

关于reactjs - React Native undefined 不是对象(评估 'Mapbox.GL.UserTrackingModes' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53339530/

相关文章:

json - react-native 如何从本地JSON文件中获取数据?

android - Alert.alert 在 React native iOS 中不起作用,但在 Android 中完全正常

javascript - leaflet-editable.js 和 mapbox.js

javascript - shouldComponentUpdate() 没有被调用

Reactjs-Popup:无法读取未定义的属性(读取 'forwardRef' )

reactjs - 如何使百分比按钮在 react-native 中工作

带大括号的 JavaScript const,其中有 2 个用冒号分隔的变量

css - create-react-app 中的条件 CSS

zooming - map 最大程度缩小时允许捏合缩放手势

javascript - 如何使用 geoJSON 层捕获传单/ map 框图像?