我正在尝试从react-native(Android)中的纬度和经度中获取当前位置,我已经正确接收了纬度和经度,但是位置的结果返回为[object object]
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 },
);
}
getData(){
Geocoder.init("My_Api");
Geocoder.from(this.state.latitude,this.state.longitude)
.then(json => {
var addressComponent = json.results[0].address_components[0];
alert(addressComponent);
})
.catch(error => console.warn(error));
}