react-native 网络请求
2021-01-18 本文已影响0人
物联白菜
let url = `https://restapi.amap.com/v3/geocode/regeo?output=xml&location=${this.state.coordinate.longitude},${this.state.coordinate.latitude}&key=a2a0942a9bcb59eb7bd0f0bb81a9817b&radius=1000&extensions=all`
fetch(url)
.then((response) => response.text())
.then((responseText) => {
let xmlContent = responseText
parseString(xmlContent, (err, result) => {
let res = JSON.parse(JSON.stringify(result.response))
console.warn('xml解析内容',res.regeocode[0].formatted_address[0]);
let str = res.regeocode[0].formatted_address[0]
this.setState({
localAddress:str,
isLoading:false,
isSuccess:true
})
});
}).done();