【发布时间】:2019-06-13 23:14:18
【问题描述】:
在我的 React 应用程序中,我希望能够使用 Geolocation API 调用具有用户当前位置的 API 端点。
我有以下方法,当用户单击按钮时会触发
findMeetings = async () => {
const location = window.navigator && window.navigator.geolocation
if (location) {
location.getCurrentPosition((position) => {
let url = `meetings/find?lat=${position.coords.latitude}&lng=${position.coords.longitude}&radius=${this.state.radius}`;
let result = await fetch(`https://localhost:44303/api/${url}`, {
method: 'get'
}).then(response => response.json());
this.setState({ meetings: result.meetings })
}, (error) => {
})
}
我收到以下错误:
解析错误:await 是保留字
我认为这是因为我在 getCurrentPosition 内部调用了一个异步方法 - 谁能帮助我了解这里的问题以及如何解决它?
【问题讨论】:
标签: reactjs async-await fetch