requestLocationUpdates interval in Android(Android中的requestLocationUpdates间隔)
问题描述
我尝试为函数 onLocationChanged 获得正确的更新速度,这是我的课程:
I try to get the correct speed in updates for the function onLocationChanged, this is my class:
public class LocationService extends Service implements LocationListener {
将 minTime 设置为 6000 并没有帮助,它会不断更新,我做错了什么?
Putting the minTime on 6000 does not help, it wil keep updating constantly, what am i doing wrong?
public void requestLocationUpdates (String provider, long minTime, float minDistance, LocationListener listener, Looper looper) {
问候
推荐答案
minTime 只是对 LocationProvider 的一个提示,并不意味着你的位置监听器会每 6 秒调用一次.您将收到更多位置更新,这取决于您的代码来选择最准确的位置.
The minTime is just a hint for the LocationProvider, and it doesn't mean that your location listener will be called once every 6 seconds. You will receive more location updates, and its up to your code to pick the most accurate one.
监控手机上的 GPS 图标.对 requestLocationUpdates 的调用将触发 GPS 来精确定位您的位置,并且如果它能够得到修复,它将向 locationlistener 发送一个或多个位置更新.(此时,您的 GPS 图标应该会在搜索位置时显示动画).
Monitor the GPS icon on your phone. A call to requestLocationUpdates will trigger the GPS to pinpoint your location, and it will send one or more location updates to the locationlistener if it's able to get a fix. (At this point, your GPS icon should be animated as it searches for a location).
在此期间,您的位置侦听器可能会收到多个位置更新.您的代码可以选择最准确的位置,然后只处理那个位置.
During that time, your locationlistener may receive several location updates. Your code can go and pick the most accurate location, and process only that one.
GPS 将位置更新发送给您的听众后,应该有一段时间不活动.(您的 GPS 图标应该会消失几秒钟).这段不活动时间应该与您的 minTime 相对应.GPS 的状态也会发生变化,因为它会进入 TEMPORARILY_UNAVAILABLE.
After the GPS has sent the location update(s) to your listener, there should be a period of inactivity. (your GPS icon should disappear for a couple of seconds). This period of inactivity should correspond with your minTime. The status of the GPS will also change, as it will be put into TEMPORARILY_UNAVAILABLE.
之后,重复相同的过程.(GPS 变为可用,您将再次收到一个或多个位置更新).
After that, the same process is repeated. (The GPS becomes AVAILABLE, and you'll again receive one or more location updates).
另外请注意,如果 GPS 无法获得位置定位,GPS 图标将保持激活状态超过 6 秒,但您不会收到位置更新.
Also take into account, if the GPS is unable to get a location fix, the GPS icon will remain active for more then 6 seconds, but you won't be receiving location updates.
您还可以通过以下方法通过监听器监控 GPS 提供商的状态:
You can also monitor the status of your GPS provider through your listener, via the following method :
public void onStatusChanged(String provider, int status, Bundle extras) {}
状态是定义在 android.location.LocationProvider 上的下列常量之一
The status is one of the following constants defined on android.location.LocationProvider
public static final int OUT_OF_SERVICE = 0;
public static final int TEMPORARILY_UNAVAILABLE = 1;
public static final int AVAILABLE = 2;
查看 了解 Android 中的 LocationListener 以获取有关minTime 行为和一个场景(包括一些日志记录)来帮助您了解正在发生的事情.
Have a look at Understanding the LocationListener in Android for an example on the minTime behavior, and a scenario (including some logging) to help you understand what's going on.
请记住,调整 LocationManager 上的 minTime 和 minDistance 参数,并根据 GPS 状态更新采取行动,可以让您微调您的用户位置开发.
Keep in mind that tweaking the minTime and minDistance parameters on the LocationManager, and acting upon GPS status updates will allow you to fine-tune your user location development.
这篇关于Android中的requestLocationUpdates间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android中的requestLocationUpdates间隔
基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01