React native 尝试结束代码时,基于React Native Maps的解析错误不断出现
我正在尝试编写一个iOS应用程序,将其导出到Expo以用作模拟器。显然,在尝试结束“render”函数时,我遇到了一个解析错误。当我试着在super下放置时,我也得到了一个“constructor expected”错误 我试着把它拆开,在末端添加更多的中间括号,改变组件的位置。似乎什么都不管用。不确定这是一个Expo问题还是我的代码不好。我还需要加一两个记号笔。。感觉要花很长时间 代码:React native 尝试结束代码时,基于React Native Maps的解析错误不断出现,react-native,React Native,我正在尝试编写一个iOS应用程序,将其导出到Expo以用作模拟器。显然,在尝试结束“render”函数时,我遇到了一个解析错误。当我试着在super下放置时,我也得到了一个“constructor expected”错误 我试着把它拆开,在末端添加更多的中间括号,改变组件的位置。似乎什么都不管用。不确定这是一个Expo问题还是我的代码不好。我还需要加一两个记号笔。。感觉要花很长时间 代码: class App extends Component, constructor(props){ t
class App extends Component,
constructor(props){
this.state = {
position: null
};
};
componentDidMount(); {
this._getCoords();
};
_getCoords = () => {
alert=("_getCoords")
navigator.geolocation.getCurrentPosition(
(position) => {
var initialPosition = JSON.stringify(position.coords);
this.setState({position: initialPosition});
let tempCoords = {
latitude: Number(position.coords.latitude),
longitude: Number(position.coords.longitude)
}
this._map.animateToCoordinate(tempCoords, 1);
}, function (error) { alert(error) },
);
};
render(); {
return (
<MapView
style= {style.map}
initialRegion={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
/>
);`
类应用程序扩展组件,
建造师(道具){
此.state={
位置:空
};
};
componentDidMount();{
这个;
};
_getCoords=()=>{
警报=(“_getCoords”)
navigator.geolocation.getCurrentPosition(
(职位)=>{
var initialPosition=JSON.stringify(position.coords);
this.setState({position:initialPosition});
让tempCoords={
纬度:数字(位置坐标纬度),
经度:数字(位置坐标经度)
}
这个._map.animateToCoordinate(tempCoords,1);
},函数(错误){alert(错误)},
);
};
render();{
返回(
);`
如果您有一些语法错误,正确的语法应该如下所示:
class App extends Component {
constructor(props) {
super(props)
this.state = {
position: null
}
}
componentDidMount() {
this._getCoords()
}
_getCoords = () => {
alert = '_getCoords'
navigator.geolocation.getCurrentPosition(
position => {
var initialPosition = JSON.stringify(position.coords)
this.setState({ position: initialPosition })
let tempCoords = {
latitude: Number(position.coords.latitude),
longitude: Number(position.coords.longitude)
}
this._map.animateToCoordinate(tempCoords, 1)
},
function(error) {
alert(error)
}
)
}
render() {
return (
<MapView
style={style.map}
initialRegion={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
}}
/>
)
}
}
类应用程序扩展组件{
建造师(道具){
超级(道具)
此.state={
位置:空
}
}
componentDidMount(){
这个。_getCoords()
}
_getCoords=()=>{
警报=“\u getCoords”
navigator.geolocation.getCurrentPosition(
位置=>{
var initialPosition=JSON.stringify(position.coords)
this.setState({position:initialPosition})
让tempCoords={
纬度:数字(位置坐标纬度),
经度:数字(位置坐标经度)
}
此._map.animateToCoords(tempCoords,1)
},
函数(错误){
警报(错误)
}
)
}
render(){
返回(
)
}
}
你能分享一些代码吗?很抱歉,经过适当的编辑。使用暗模式无法查看我需要如何输入代码。类应用程序扩展组件,
。组件的大括号在哪里???复制时是否丢失了?如果没有,请分享App.js
的完整代码。