有一种方法可以避免navigator.geolocation.getCurrentPosition被缓存? [英] There is a way to avoid navigator.geolocation.getCurrentPosition from be cached?

查看:482
本文介绍了有一种方法可以避免navigator.geolocation.getCurrentPosition被缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在React Native App中使用navigator.geolocation.getCurrentPosition()函数来获取设备的位置,但是我一直在阅读,有时如果该函数指出您的信号不好,它可能会返回缓存的位置.有一种方法可以避免返回缓存的位置,而是返回一个错误?

I'm using in my React Native App the navigator.geolocation.getCurrentPosition() function to get the location of my device but I have been reading that sometimes if the function notes that you have no good signal it could return the cached location. There is a way to avoid the returning cached location and return an error instead?

推荐答案

我找到了解决方案!

问题是我没有将超时时间传递给选项,然后设备试图立即获取位置,因此它无法做到这一点,而是从缓存中获取.

The problem was that I wasn't passing the timeout time to the options and then the device was trying to get the location immediately, so it wouldn't be able to do that and was getting from the cache.

现在大约需要3秒钟才能获得位置,但效果很好!

Now it is getting like 3 seconds to get the location but works fine!

这篇关于有一种方法可以避免navigator.geolocation.getCurrentPosition被缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆