有人可以帮助我解决此错误吗?
我从YouTube上关于React-Native-Maps的教程中学习并复制了代码,以显示当前位置。链接:https://www.youtube.com/watch?v=MqLC0kOqrwk
错误是:超级表达式必须为null或函数
我正在使用最新版本的React-Native-Maps React-Native-Maps版本:“ ^ 0.22.1”,
import React from 'react';
import {
AppRegistry,
Component,
StyleSheet,
View,
Text,
screen,
Dimensions,
TouchableOpacity,
Platform,
} from 'react-native';
import MapView from 'react-native-maps';
import Strings from '../utils/Strings';
var styles = require('../../assets/files/Styles');
const {height, width} = Dimensions.get('window');
const SCREEN_HEIGHT = height
const SCREEN_WIDTH = width
const ASPECT_RATIO = width / height
const LATITUDE_DELTA = 0.00922;
const LONGITUDE_DELTA = LATITUDE_DELTA * ASPECT_RATIO;
export default class Track extends Component {
static navigationOptions = {
title: `${Strings.ST6}`,
};
constructor(props) {
super(props)
this.state = {
initialPosition: {
latitude: 0,
longitude: 0,
latitudeDelta: 0,
longitudeDelta: 0
},
markerPosition: {
latitude: 0,
longitude: 0
}
}
}
watchID = null
componentDidMount(){
navigator.geolocation.getCurrentPosition((position) => {
var lat = parseFloat(position.coords.latitude)
var long = parseFloat(position.coords.longitude)
var initialRegion = {
latitude: lat,
longitude: long,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGTITUDE_DELTA
}
this.getState({initialPosition: initialRegion})
this.getState({markerPosition: initialRegion})
},
(error) => alert(JSON.stringify(error)),
{enableHighAccuracy: true, timeout: 20000, maximumAge: 1000})
this.watchID = navigator.geolocation.watchPosition((position) => {
var lat = parseFloat(position.coords.latitude)
var long = parseFloat(position,coords,longitude)
var lastRegion = {
latitude: lat,
longitude: long,
longitudeDelta: LONGTITUDE_DELTA,
latitudeDelta: LATITUDE_DELTA
}
this.setState({initialPosition: lastRegion})
this.setState({markerPosition: lastRegion})
})
}
componentWillUnmount() {
navigator.geolocation.clearWatch(this.watchID)
}
render() {
return(
<View style={style.container}>
<MapView
style={styles.map}
region={this.state.initialPosition}>
<MapView.Marker>
coordinate={this.state.markerPosition}
<View Style={styles.radius}>
<View Style={styles.marker}>
</View>
</View>
</MapView.Marker>
</MapView>
</View>
);
}
}
我猜错误是在
附近constructor(props) { super(props)
但是我在这里没有看到错误,超级应该没问题,即使我删除了(道具),结果也是一样。
答案 0 :(得分:0)
在代码class Track extends Component
上,您忘记了调用 react 属性。请更改您的代码为class Track extends React.Component
。
因为您只是调用Component,而React不知道'Component'的来源