【发布时间】:2019-05-01 11:01:17
【问题描述】:
我想获取当前位置它适用于当前的 react native 版本,但我希望它适用于 react native 版本 0.55.1
我试过这样 它有效
constructor(props) {
super(props);
this.state = {
latitude: null,
longitude: null,
error:null,
};
}
componentDidMount() {
navigator.geolocation.getCurrentPosition(
(position) => {
console.log("wokeeey");
console.log(position);
this.setState({
latitude: position.coords.latitude,
longitude: position.coords.longitude,
error: null,
});
},
(error) => this.setState({ error: error.message }),
{ enableHighAccuracy: false, timeout: 200000, maximumAge: 1000 },
);
}
我用这个打印
<View>
<Text> Longitude:- {this.state.latitude} </Text>
<Text> Latitude:- {this.state.longitude} </Text>
<Text> {this.state.error} </Text>
</View>
但是对于 react native 0.55.1 它不起作用。 请帮助我该怎么办?
【问题讨论】:
标签: react-native geolocation geocoding