【问题标题】:React Native undefined is not an object (evaluating 'Mapbox.GL.UserTrackingModes')React Native undefined 不是一个对象(评估'Mapbox.GL.UserTrackingModes')
【发布时间】:2018-11-16 14:12:27
【问题描述】:

我开始使用 mapbox 进行本机反应,但是,我在使用 npm 或 yarn 安装它并且导入到我的项目时遇到了这个问题,我有点确定这是 mapbox api 还是方式的问题我试图实现这是错误的。

使用 react 原生版本:

  • react-native-cli: 2.0.1
  • 反应原生:0.57.3

反应原生:0.57.3

地图.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时出现这个错误。

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


【解决方案1】:

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

【讨论】:

  • iOS 模拟器上出现同样的错误。 iOS 13. 那怎么样?
猜你喜欢
  • 2018-11-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-04
  • 2018-03-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多