Reactjs 反应本地地理定位信号强度
如何使用react本地地理定位获取信号强度状态?如果可用,如何在react本机摄像头上显示此强度状态 我的代码是:Reactjs 反应本地地理定位信号强度,reactjs,react-native,geolocation,Reactjs,React Native,Geolocation,如何使用react本地地理定位获取信号强度状态?如果可用,如何在react本机摄像头上显示此强度状态 我的代码是: class GeolocationExample extends Component { constructor(props) { super(props); this.state = { latitude: null, longitude: null, accurac
class GeolocationExample extends Component {
constructor(props) {
super(props);
this.state = {
latitude: null,
longitude: null,
accuracy: null,
error: null,
};
}
componentDidMount() {
navigator.geolocation.getCurrentPosition(
(position) => {
this.setState({
latitude: position.coords.latitude,
longitude: position.coords.longitude,
accuracy: position.coords.accuracy,
error: null,
});
},
(error) => this.setState({ error: error.message }),
{ enableHighAccuracy: true, timeout: 5000, maximumAge: 0 },
);
//console.log(this.state.latitude);
}
render() {
return (
<View style={{ flexGrow: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Latitude: {this.state.latitude}</Text>
<Text>Longitude: {this.state.longitude}</Text>
<Text>Accuracy: {this.state.accuracy}</Text>
{this.state.error ? <Text>Error: {this.state.error}</Text> : null}
</View>
);
}
}
export default GeolocationExample;
class GeolocationExample扩展组件{
建造师(道具){
超级(道具);
此.state={
纬度:空,
经度:空,
准确度:空,
错误:null,
};
}
componentDidMount(){
navigator.geolocation.getCurrentPosition(
(职位)=>{
这是我的国家({
纬度:位置。坐标。纬度,
经度:position.coords.longitude,
准确度:位置、坐标、准确度,
错误:null,
});
},
(error)=>this.setState({error:error.message}),
{enableHighAccurance:true,超时:5000,最大值:0},
);
//console.log(this.state.latitude);
}
render(){
返回(
纬度:{this.state.Latitude}
经度:{this.state.Longitude}
准确性:{this.state.accurity}
{this.state.error?错误:{this.state.error}:null}
);
}
}
导出默认地理位置示例;