1 回答
TA贡献1785条经验 获得超8个赞
试试这个方法
callApi(){
console.log(this.state.coords.latitude + " " + this.state.coords.longitude);
region = getapi(this.state.coords.latitude, this.state.coords.longitude)
this.setState({region})
console.log("TEMP: " + region);
hot = getHotBarb(this.state.region)
this.setState({hot})
rated = getRatedBarb(this.state.region)
this.setState({rated})
offer = getOfferBarb(this.state.region)
this.setState({offer})
this.setState({loading: false})
}
getCurrentPosition(){
Geolocation.getCurrentPosition(info => {
console.log(info.coords.latitude + " " + info.coords.longitude);
this.setState({coords: {latitude: info.coords.latitude, longitude: info.coords.longitude, latitudeDelta: this.LATITUDE_DELTA, longitudeDelta: this.LONGITUDE_DELTA}},
() => this.callApi(); // call api here
)
}, error => Alert.alert('Error', JSON.stringify(error)),
{enableHighAccuracy: true, timeout: 20000, maximumAge: 1000});
}
componentDidMount(){
this.getCurrentPosition();
}
添加回答
举报