React Native地理定位API中的getCurrentPosition只运行10%的时间?

我运行的是阵营本地getCurrentPosition地理位置功能内componentDidMount这样的:React Native地理定位API中的getCurrentPosition只运行10%的时间?

async componentDidMount(){ 

alert('comp mounting');

await navigator.geolocation.getCurrentPosition(

(position) => {

alert("state of lat in callback is "+position.coords.latitude);

this.setState({lat: position.coords.latitude, long: position.coords.longitude});

},

(error) => {alert("there was an error getting location")},

{enableHighAccuracy: true}

);

}

它惊动了纬度我第一次运行它,也许其他几个超时约40的尝试。我认为所有这些运行都没有asyncawait。大约90%的时间既没有成功回调中的警报,也没有错误回调中的警报运行。

我把异步和等待,因为我想这个请求花了太长时间(尽管第一次立即运行)。

我需要将位置信息传递给子组件。

React Native默认的Geolocation库不是很好,或者我做错了什么?我应该切换到使用独立的iOS/Android地理位置选项吗?

回答:

alert()调用似乎是问题所在。一旦我删除alert()调用它开始工作。

以上是 React Native地理定位API中的getCurrentPosition只运行10%的时间? 的全部内容, 来源链接: utcz.com/qa/260754.html

回到顶部