问题描述
我正在开发Ionic App,并希望解决Geolocation Watch Position的问题。我想每隔1分钟后收集数据,而不是在5秒后。我的代码如下,
I am working on Ionic App and want to fix issue for Geolocation Watch Position. I want to get data after every 1 minutes not after 5 sec. My code is as following,
var opti = { enableHighAccuracy: false, timeout:60000, maximumAge: 0 };
navigator.geolocation.watchPosition(success_loc, error_loc, opti);
我在1分钟后使用超时60000给出结果,但它在5秒内给出结果(默认时间)。需要帮助来解决这个问题。
I am using timeout 60000 for giving result after 1 minutes but it is giving result in 5 sec(default time). Need help to fix this problem.
推荐答案
您需要将maximumAge设置为60000.根据文档,超时选项指示准许获得职位的时间。所以,这不是你感兴趣的东西。而是使用maximumAge。当maximumAge设置为60000时,一分钟内将使用缓存位置,而不是获取新位置。
You need to set the maximumAge to 60000. As per the docs, the timeout option indicates the time allowed for obtaining the position. So, this is not what something you are interested. Instead, use the maximumAge. When the maximumAge is set to 60000, for one minute the cached position will be used instead of obtaining a new one.
这篇关于WatchPosition在地理定位中超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!