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

问题描述 投票:3回答:1

我开始使用mapbox for native native,但是,当我使用npm或yarn安装它时我遇到了这个问题,当导入到我的项目时,我确定这是mapbox api的问题还是我的方式试图实现这一点是错误的。

使用react native版本:

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

反应原生: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
  },
});
reactjs react-native mapbox mapbox-gl-js mapbox-gl
1个回答
-1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.