Javascript Resact Native Navigation v1在StatabBaseDapp中崩溃
当我在startTabBasedApp(我的3个选项卡)中导航我的应用程序时,要呈现的第一个屏幕是EventMap.js,这就是我的应用程序崩溃的地方。我只是不知道为什么它会崩溃,我试着把Javascript Resact Native Navigation v1在StatabBaseDapp中崩溃,javascript,react-native,react-native-android,wix-react-native-navigation,Javascript,React Native,React Native Android,Wix React Native Navigation,当我在startTabBasedApp(我的3个选项卡)中导航我的应用程序时,要呈现的第一个屏幕是EventMap.js,这就是我的应用程序崩溃的地方。我只是不知道为什么它会崩溃,我试着把console.log放在我的所有代码中,但没有出现错误 所以这里的主要问题是EventMap.js,因为当我尝试在startTabBasedApp(主选项卡)中删除EventMap.js,然后卸载应用程序,运行react native run android,打开应用程序导航选项卡(2)时,它工作正常 我试图
console.log
放在我的所有代码中,但没有出现错误
所以这里的主要问题是EventMap.js,因为当我尝试在startTabBasedApp(主选项卡)中删除EventMap.js,然后卸载应用程序,运行react native run android
,打开应用程序导航选项卡(2)时,它工作正常
我试图在我的应用程序中做的是,当用户打开它并将其导航到EventMap.js时,我希望立即获得用户的位置,就像在抓取应用程序中一样
如何在不破坏应用程序的情况下实现这一点
以下是我的EventMap.js代码
class EventMap extends Component {
constructor(props) {
super(props);
this.state = {
focusedLocation: {
latitude: 0,
longitude: 0,
latitudeDelta: 0.01,
longitudeDelta: Dimensions.get('window').width / Dimensions.get('window').height * 0.01
},
locationChosen: false,
markerPosition: {
latitude: 0,
longitude: 0
}
}
}
componentDidMount() {
this.didMountGetUserLocation();
};
//This is getting the location and exactly/automatically when they open
didMountGetUserLocation = () => {
navigator.geolocation.getCurrentPosition(pos => {
var lat = parseFloat(pos.coords.latitude)
var long = parseFloat(pos.coords.longitude)
var initialRegion = {
latitude: lat,
longitude: long,
latitudeDelta: 0.01,
longitudeDelta: Dimensions.get('window').width / Dimensions.get('window').height *0.01
};
this.setState({focusedLocation: initialRegion})
this.setState({locationChosen: true})
this.setState({markerPosition: initialRegion})
},
err => {
console.log(err);
});
};
pickLocationHandler = (event) => {
const coords = event.nativeEvent.coordinate;
//For animation of map
this.map.animateToRegion({
...this.state.focusedLocation,
latitude: coords.latitude,
longitude: coords.longitude
});
this.setState(prevState => {
return {
focusedLocation: {
...prevState.focusedLocation,
latitude: coords.latitude,
longitude: coords.longitude
},
locationChosen: true
};
});
};
getLocationHandler = () => {
navigator.geolocation.getCurrentPosition(pos => {
const coordsEvent = {
nativeEvent: {
coordinate: {
latitude: pos.coords.latitude,
longitude: pos.coords.longitude
}
}
};
this.pickLocationHandler(coordsEvent);
},
err => {
console.log(err);
alert("Fetching failed");
})
};
render() {
let marker = null;
if(this.state.locationChosen) {
marker = <MapView.Marker coordinate={this.state.markerPosition}/>
}
return(
<View style={{zIndex: -1}}>
<TouchableOpacity onPress={this.getLocationHandler} style={styles.iconContainer}>
<Icon name="md-locate" size={30} color="blue"/>
</TouchableOpacity>
<MapView
style={styles.map}
initialRegion={this.state.focusedLocation}
onPress={this.pickLocationHandler}
showsUserLocation={true}
ref={ref => this.map = ref} //For animating map movement
>
{marker}
</MapView>
</View>
);
}
}
类事件映射扩展组件{
建造师(道具){
超级(道具);
此.state={
焦点位置:{
纬度:0,
经度:0,,
纬度德尔塔:0.01,
longitudeDelta:Dimensions.get('window')。宽度/尺寸。get('window')。高度*0.01
},
所选位置:false,
标记位置:{
纬度:0,
经度:0
}
}
}
componentDidMount(){
this.didMountGetUserLocation();
};
//这是在它们打开时准确/自动获取位置
didMountGetUserLocation=()=>{
navigator.geolocation.getCurrentPosition(位置=>{
var lat=parseFloat(位置坐标纬度)
var long=parseFloat(位置坐标经度)
变量初始值区域={
纬度:纬度,
经度:长,
纬度德尔塔:0.01,
longitudeDelta:Dimensions.get('window')。宽度/尺寸。get('window')。高度*0.01
};
this.setState({focusedLocation:initialRegion})
this.setState({locationselected:true})
this.setState({markerPosition:initialRegion})
},
错误=>{
控制台日志(err);
});
};
pickLocationHandler=(事件)=>{
const coords=event.nativeEvent.coord;
//地图动画
this.map.animateToRegion({
…此.state.focusedLocation,
纬度:坐标,纬度,
经度:坐标
});
this.setState(prevState=>{
返回{
焦点位置:{
…prevState.focusedLocation,
纬度:坐标,纬度,
经度:坐标
},
地点选择:正确
};
});
};
getLocationHandler=()=>{
navigator.geolocation.getCurrentPosition(位置=>{
常数协调={
nativeEvent:{
协调:{
纬度:位置坐标纬度,
经度:位置坐标经度
}
}
};
这个.pickLocationHandler(coordsEvent);
},
错误=>{
控制台日志(err);
警报(“获取失败”);
})
};
render(){
设marker=null;
如果(此.state.locationselected){
标记=
}
返回(
this.map=ref}//用于设置贴图移动动画
>
{marker}
);
}
}