React Native undefined is not an object (evaluating 'Mapbox.GL.UserTrackingModes')

Viewed 1754

I started using mapbox for react native, however, I´m having this issue when installing it using both npm or yarn and when importing to my project, I´m bit sure if this is an issue with mapbox api or the way I'm trying to implement this is wrong.

Using react native version:

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

react-native: 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
  },
});
1 Answers

Make sure you are setting dependencies properly on the android gradle files

Related